📄 unit_outstore.pas
字号:
unit unit_outStore;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask, DBCtrls, Buttons, Grids, DBGrids, ExtCtrls, DBCGrids, Db,
DBTables,math;
type
TFormOutStore = class(TForm)
Bevel2: TBevel;
cmdAdd: TBitBtn;
cmdDelete: TBitBtn;
DBBarcode: TDBEdit;
cmdConfirm: TBitBtn;
edtInvoNO: TEdit;
edtBarcode1: TEdit;
Bevel3: TBevel;
StaticText1: TStaticText;
stBarcode1: TStaticText;
stBarcode: TStaticText;
Label7: TLabel;
DBOutQty: TDBEdit;
DbgridInbooks: TDBGrid;
stname: TStaticText;
StaticText5: TStaticText;
stQty: TStaticText;
StaticText9: TStaticText;
stPerQty: TStaticText;
Query1: TQuery;
Query1codename: TStringField;
Query1barcode: TStringField;
Query1name: TStringField;
DSStoreQ: TDataSource;
gbxUnit: TGroupBox;
rbnUnits: TRadioButton;
rbnUnit2: TRadioButton;
stUnits: TStaticText;
QueryBill: TQuery;
rbnUnit3: TRadioButton;
PanelWait: TPanel;
StaticText4: TStaticText;
stPrice: TStaticText;
Label4: TLabel;
DBSalePrice: TDBEdit;
Label1: TLabel;
DBMemo1: TDBEdit;
Panel1: TPanel;
DBGrid1: TDBCtrlGrid;
DBEdit1: TDBEdit;
Button1: TButton;
StaticText7: TStaticText;
stExp_date: TStaticText;
stQty1: TStaticText;
lblCompany: TLabel;
PanelDirect: TPanel;
MaskEdit1: TMaskEdit;
StaticText10: TStaticText;
Query1barcode1: TStringField;
procedure DBBarcodeKeyPress(Sender: TObject; var Key: Char);
procedure cmdAddClick(Sender: TObject);
procedure cmdconfirmClick(Sender: TObject);
procedure DBBarcodeExit(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure DBGrid1Click(Sender: TObject);
procedure DBEdit1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure cmdDeleteClick(Sender: TObject);
procedure DBBarcodeEnter(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure DBSalePriceKeyPress(Sender: TObject; var Key: Char);
procedure DBOutQtyKeyPress(Sender: TObject; var Key: Char);
procedure rbnUnitsKeyPress(Sender: TObject; var Key: Char);
procedure rbnUnit2KeyPress(Sender: TObject; var Key: Char);
procedure edtInvoNOExit(Sender: TObject);
procedure edtInvoNOKeyPress(Sender: TObject; var Key: Char);
procedure edtBarcode1KeyPress(Sender: TObject; var Key: Char);
procedure rbnUnit3KeyPress(Sender: TObject; var Key: Char);
procedure Query1CalcFields(DataSet: TDataSet);
procedure gbxUnitExit(Sender: TObject);
procedure DBMemo1KeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
procedure lblCompanyClick(Sender: TObject);
procedure DBBarcodeChange(Sender: TObject);
procedure edtBarcode1Exit(Sender: TObject);
procedure rbnUnit2Click(Sender: TObject);
procedure DBOutQtyExit(Sender: TObject);
procedure edtBarcode1Change(Sender: TObject);
procedure Query1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
private
{ Private declarations }
nId:integer;
procedure Addempty;
procedure ChgSaleprice;
Function ChkNoStore:boolean;
public
{ Public declarations }
bError:boolean;
ErrorInvono:string;
nNowQty,nNowQty1:real;
nItemIndex:integer;
nPay,nPay1:Currency;
myInvono,myName:string;
sDept,sSaler,sBuyer,sWarehouseman,sOthers:string;
end;
var
FormOutStore: TFormOutStore;
implementation
uses datamodule1, goods, Unit5, unit_showcompany,dataMrp, dlgMsg;
{$R *.DFM}
procedure TFormOutStore.DBBarcodeKeyPress(Sender: TObject; var Key: Char);
var
seekvalue:string;
nTimes:integer;
begin
seekvalue:=dbBarcode.text;
nTimes:=length(seekvalue);
if (nTimes>DataPub.nSysLevel3) and (key=chr(13)) then
dbOutQty.Setfocus;
end;
procedure TFormOutStore.cmdAddClick(Sender: TObject);
begin
with Datamodule2.outmp1 do
begin
if dataPub.nDatabaseTypeTmp=DataAccess then
begin
if state in[ dsEdit,dsInsert] then
post;
close;
open;
end;
addempty;
//如果用拼音法,下次该控件获得焦点
if (trim(edtBarcode1.text)<>'') and not datapub.bZone then
begin
edtBarcode1.text:='';
edtBarcode1.setfocus; end
else dbBarcode.setfocus;
end;
end;
procedure TFormOutStore.cmdconfirmClick(Sender: TObject);
var
seekvalue,sKind,sysInvono,sErrInfo:string;
nSeq:integer;
nQty,nLastQty,nPerQty,nBal_qty,nPrice,nProfit,nOldPrice,nPayed,nInprice,ncost:real;
options:TLocateOptions;
bClear:boolean;
s1,s2:string;
dOutDate:TDatetime;
begin
nSeq:=1;
bClear:=true;
nPayed:=0;
dOutDate:=strTodate(MaskEdit1.text);
sErrInfo:=' 数据错误'+#13;
dbGridInbooks.DefaultDrawing:=false;
try
if dataPub.nDatabaseTypeTmp=DataAccess then
dataModule2.outmp1.refresh
else begin
dataModule2.outmp1.applyupdates;
dataModule2.outmp1.close;
dataModule2.outmp1.open;
end;
except
application.MessageBox('数据写入错误! ','错误',MB_ok);
end;
with dataModule2 do
begin
if Qdelete.active then qDelete.close;
QDelete.sql.clear;
QDelete.sql.add('select sum(salePrice*outQty*cal_qty) as amount from outmp1 where invono= :invono');
QDelete.params[0].asstring:=myInvono;
QDelete.Open;
nPay:=QDelete.fieldbyname('amount').asCurrency;
end;
payDlg.bPos:=false;
payDlg.sCusId:=myInvono;
payDlg.nPay:=nPay;
payDlg.sOutDate:=maskEdit1.text;
if dataPub.hotelspe>10 then //仓库不出现销售框
begin
if not bError then
begin
PayDlg.showmodal;
if dataPub.bNetFresh then //网络版,开始写时要重新读入store
begin //主机:不影响速度
datamodule2.TableStore.close; //从机:效率会降低。
datamodule2.TableStore.open; //共享冲突:明显降低
end;
sysInvoNo:=PayDlg.Invono;end
else begin bError:=false; //发生错误,记住编号,不用打印两次
sysInvono:=ErrorInvono;
datamodule2.tablestore.cancelUpdates;
dataModule2.tablestore.refresh;
cmdConfirm.caption:='销售(&P)' end
end else
sysInvoNo:=DataPub.getInvono;
// read the system invono,from 0001-9999 every day
if (PayDlg.ModalResult =idOk) or (dataPub.hotelspe<10) then
begin
PanelWait.Visible:=true;
PanelWait.Repaint;
dataModule2.database1.StartTransAction;
try
Datamodule2.outmp1.First;
with datamodule2 do
repeat
begin
seekvalue:=outmp1.FieldByName('barCode').asstring;
if Length(trim(seekvalue))>1 then
begin
nQty:=outmp1.FieldByname('OutQty').asfloat;
nLastQty:=0;
nBal_Qty:=nQty;
nPayed:=nPayed+nQty;
nProfit:=0;
nCost:=0;
with tableStore do
begin
//if findkey([seekvalue]) and (nQty>0) then //数量<= 0,不修改库存
if findkey([seekvalue]) and (abs(nQty)>0) then //数量<= 0,退货单
begin
nPerQty:=Fieldbyname('perqty').asfloat;
if nPerQty<1 then nPerQty:=1;
//零数单位 ( 件数=零数 ,规格>1)
if (fieldbyname('unit2').asstring=outmp1['units']) and (nPerQty>1) then
begin
nLastQty:=outmp1.FieldByname('OutQty').asfloat;
nQty:=0;
nBal_Qty:=nLastQty/nPerQty;
nBal_Qty:=int(nBal_Qty*100)/100; //保留两位小数
nProfit:=nLastQty*(outmp1['salePrice']-fieldbyname('inprice2').ascurrency);
nInprice:=fieldbyname('inprice2').ascurrency;
end else
begin
if datamodule2.Outmp1['cal_qty']>1 then //件数,按零数价
begin
nProfit:=nQty*nPerQty*(outmp1['salePrice']-fieldbyname('inprice2').ascurrency);
nInprice:=fieldbyname('inprice2').ascurrency*nPerQty;
end else //件数
begin
nProfit:=nQty*(outmp1['salePrice']-fieldbyname('inprice').ascurrency);
nInprice:=fieldbyname('inprice').ascurrency;
end;
end;
//先进先出,nQty
if dataPub.bFIFO then
if nBal_Qty>0 then
nProfit:=DataPub.DoFIFO(nQty,nLastQty,outmp1['saleprice']*outmp1['cal_qty'],nPerQty,nInprice,seekvalue,outmp1['units'])
else //负数退货
nProfit:=DataPub.BackFIFO(-nQty,-nLastQty,outmp1['salePrice'],nPerQty,nInprice,seekvalue,outmp1['units']);
nCost:=(nQty+nLastQty)*outmp1['saleprice']*outmp1['cal_qty']-nProfit;
//出仓价为 0,为报损单;
if (outmp1['saleprice'] <= 0) and datapub.bZeroProfit then
nProfit := 0;
//负数退货 不计利润
if (nBal_Qty < 0) then
nProfit := 0;
//负数退货 , 不计利润,成本
if (nBal_Qty < 0 ) then nCost:=0;
edit;
if datapub.bAutoIO then
FieldByname('OutQty').asfloat:=FieldByname('OutQty').asfloat+nBal_Qty;
if (nQty=0) then //零数出仓
begin
nPerQty:=fieldbyname('perqty').asfloat;
//仓的零数小于出仓值,从件数中补充
if (FieldByname('LastQty').asfloat-nLastQty) <0 then
begin
nQty:=ceil((nLastQty-FieldByname('LastQty').asfloat)/nPerQty);
FieldByname('Qty').asfloat:=FieldByname('Qty').asfloat-nQty;
end;
FieldByname('LastQty').asfloat:=nQty*nPerQty+FieldByname('LastQty').asfloat-nLastQty;
end else
FieldByname('Qty').asfloat:=FieldByname('Qty').asfloat-nQty;
nBal_qty:=FieldByname('Qty').asfloat-nBal_Qty;
end;//end of find key
end; // end of tablebooks
//second, update in CusBill,非仓库版
if (length(myInvoNO)>2) and (length(seekvalue)>3) and (dataPub.hotelspe > 10 ) then
begin
sErrInfo:='客户价格表更新错误'+#13;
nPrice:=outmp1.FieldByname('salePrice').asfloat;
if dataPub.bZone and (edtBarcode1.text<>'') then
DataPub.UpCusbill(edtbarcode1.text,seekvalue,outmp1.FieldByname('oldPrice').asfloat,nPrice)
else
DataPub.UpCusbill(myInvono,seekvalue,outmp1.FieldByname('oldPrice').asfloat,nPrice);
end;
//管理有限期,即每次要写入有效期
if dataPub.bExpDate then
DataPub.UpExpDate(outmp1['outqty'],outmp1['seq'],outmp1['invo']);
//insert into outstore
nPrice:=outmp1.fieldbyname('saleprice').asfloat*outmp1.fieldbyname('cal_qty').asfloat;
nQty:= outmp1.fieldbyname('outqty').asfloat;
s1:=outmp1.fieldbyname('memo1').asstring;
s2:=outmp1.fieldbyname('units').asstring;
sErrInfo:='出仓单增加错误'+#13;
datapub.InsertIOStore(bClear,2,nSeq,sysInvono,seekvalue,
s2,s1,
nQty,nPrice,nProfit,0,0,ncost,
dOutDate,outmp1['pro_date'],outmp1['exp_date']);
if bClear then bClear:=false;// not clear sql
inc(nSeq);
end; //begin length>1
outmp1.next;
end //repeat
until outmp1.EOF ;
// 销售版
if dataPub.hotelspe > 10 then
begin
myName:=payDlg.Cusname; //客户
sSaler:=payDlg.SalerName; //业务员
sBuyer:=payDlg.SubName; //客户分区
if DataPub.bWholeSale then sOthers:='批发:' else sOthers:='零售:';
sOthers:=sOthers+payDlg.PayType ;
nPayed:=payDlg.HavePayed;
end else //仓库版
myName:=sDept;
with dataModule2 do
begin
sErrInfo:='库存表更新错误'+#13;
tableStore.applyupdates;
sErrInfo:='帐单表增加错误'+#13;
if sOthers='预付卡' then //buyer+卡号
dataPub.InsertLedger(sysInvoNo,myname,'O',sSaler,sBuyer+PayDlg.Cardno,sWarehouseman,sOthers ,npay,nPayed,dOutdate)
else
dataPub.InsertLedger(sysInvoNo,myname,'O',sSaler,sBuyer,sWarehouseman,sOthers,npay,nPayed,dOutdate);
if sOthers='预付卡' then //从预付卡中减余额
datapub.UpDeposit(payDlg.Cardno,nPay);
outmp1.close;
sErrInfo:='临时表删除错误'+#13;
if dataPub.bSafe then
begin
QDelete.sql.Clear;
Qdelete.sql.add('update outmp1 set barcode= :barcode,name= :name, invo= :invo,invono= :invono1,saleprice=0,outqty=0 where invono= :invono');
QDelete.params[0].asstring:='0';
QDelete.params[1].asstring:='0';
QDelete.params[2].asstring:='';
QDelete.params[3].asstring:='0';
QDelete.params[4].asstring:=myInvono;
Qdelete.execsql;
end;
QDelete.sql.Clear;
Qdelete.sql.add('delete from outmp1 where invono= :invono');
if datapub.bSafe then
QDelete.params[0].asstring:='0'
else
QDelete.params[0].asstring:=myInvono;
Qdelete.execsql;
end;
dataModule2.database1.commit;
edtInvono.setfocus;
with dataModule2.outmp1 do
begin
filter:='';
filtered:=false;
open;
first;
if Eof and DataPub.bCloseOut then self.close;
end;
except
sErrInfo:=sErrInfo+#13;
application.MessageBox(pchar(sErrInfo),'错误',MB_ok);
bError:=true;
ErrorInvono:=sysInvono;
cmdConfirm.caption:='再销售(&P)';
dataModule2.database1.rollback;
// datamodule2.tableStore.open;
end;
PanelWait.Visible:=false;
end; // end of showmodal
dbGridInbooks.DefaultDrawing:=true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -