📄 ar_enter_passsaleinvoice.pas
字号:
unit Ar_Enter_PassSaleInvoice;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Check_Body, Db, ActnList, AdODB, Grids, DBGridEh, StdCtrls,
ExtCtrls, ComCtrls, ToolWin, Mask, ExtEdit;
Type
TFrm_Ar_Enter_PassSaleInvoice = Class(TFrm_Base_Check_Body)
Label4: TLabel;
Edt_InvoiceNo: TEdit;
Label15: TLabel;
Label3: TLabel;
MEdt_CreateDate: TMaskEdit;
Label8: TLabel;
Edt_CurrencyCode: TExtEdit;
Lab_CurrencyName: TLabel;
Lab_SaleDeptName: TLabel;
Label9: TLabel;
Edt_ExchangeRate: TEdit;
Label17: TLabel;
Edt_TotalTaxAmount: TEdit;
Label2: TLabel;
Edt_InvoiceType: TEdit;
Label18: TLabel;
Cx_Assess: TComboBox;
Edt_AssessorEmployeeCode: TEdit;
Label19: TLabel;
Label11: TLabel;
Label1: TLabel;
Edt_CustomerCode: TExtEdit;
Label14: TLabel;
Edt_RemArk: TEdit;
Lab_SaleEmployeeName: TLabel;
Lab_SaleTermName: TLabel;
Edt_CreateEmployeeCode: TExtEdit;
Label20: TLabel;
edt_CustomerName: TExtEdit;
edt_CurrencyName: TExtEdit;
edt_CreateName: TExtEdit;
edt_assessName: TEdit;
AdoQry_BodyInvoiceNo: TStringField;
AdoQry_BodyShipNo: TStringField;
AdoQry_BodyShiplineNo: TIntegerField;
AdoQry_BodyItemCode: TStringField;
AdoQry_BodyItemName: TStringField;
AdoQry_BodyItemflag: TStringField;
AdoQry_BodyUomName: TStringField;
AdoQry_BodyShipQty: TFloatField;
AdoQry_BodyTaxPrice: TFloatField;
AdoQry_BodyTaxAmount: TFloatField;
AdoQry_BodyNoTaxPrice: TFloatField;
AdoQry_BodyNoTaxAmount: TFloatField;
AdoQry_BodyDiSCountRate: TFloatField;
AdoQry_BodyDiSCountAmount: TFloatField;
AdoQry_BodyRemArk: TStringField;
procedure Act_CheckExecute(Sender: TObject);
procedure Act_CancelCheckExecute(Sender: TObject);
private
{ Private declarations }
public
procedure InitForm(AdOConnection:TAdOConnection;FormStatus:String;
AdoQuery:TAdoQuery);Override;
procedure InitControls; Override;
function enoughCurrentInv(whCode,WhPositionCode,ItemCode:string;qty:real):boolean;
function enoughBatchInv(Batchno,whCode,WhPositionCode:string;qty:real):boolean;
procedure updateslolineqty(slono:string;slolineno:integer;qty:real;Addorreduce:integer);
procedure reduceItemqty(ItemCode:string;qty:real;Addorreduce:integer);
procedure reduceCurrentInv(whCode,WhPositionCode,ItemCode:string;qty:real;Addorreduce:integer);
procedure reduceBatchInv(Batchno,whCode,WhPositionCode:string;qty:real;Addorreduce:integer);
procedure updateqty(Addorreduce:integer);
{ Public declarations }
end;
var
Frm_Ar_Enter_PassSaleInvoice: TFrm_Ar_Enter_PassSaleInvoice;
implementation
uses Sys_Global;
{$R *.DFM}
{ TFrm_Sa_Enter_PassShipOrder }
procedure TFrm_Ar_Enter_PassSaleInvoice.InitControls;
begin
inherited;
end;
procedure TFrm_Ar_Enter_PassSaleInvoice.InitForm(
AdOConnection: TAdOConnection; FormStatus: String; AdoQuery: TAdoQuery);
var
SqlText:string;
begin
inherited;
With AdoQuery do
begin
Edt_InvoiceNo.Text :=fieldbyname('InvoiceNo').AsString;
Edt_CustomerCode.Text:=fieldbyname('CustomerCode').AsString;
Edt_CustomerName.text:=fieldbyname('CustomerName').AsString;
case fieldbyname('InvoiceType').asinteger of
0 : edt_InvoiceType.Text:='0 普通发票 ';
1 : edt_InvoiceType.Text:='1 专用发票';
end;
Edt_CreateEmployeeCode.Text:=fieldbyname('CreateEmployeeCode').AsString;
edt_CreateName.Text:=fieldbyname('createEmployeeName').asstring;
MEdt_CreateDate.Text:=Formatdatetime('yyyy.mm.dd',fieldbyname('CreateDate').asdatetime);
Edt_CurrencyCode.Text:=fieldbyname('CurrencyCode').AsString;
edt_CurrencyName.Text:=fieldbyname('currencyName').asstring;
Edt_ExchangeRate.Text:=fieldbyname('ExchangeRate').AsString;
Edt_RemArk.Text:=fieldbyname('RemArk').AsString;
Edt_TotalTaxAmount.Text:=fieldbyname('TotalTaxAmount').AsString;
Edt_AssessorEmployeeCode.Text:=fieldbyname('AssessorEmployeeCode').AsString;
edt_assessName.Text:=fieldbyname('assessName').asstring;
Cx_Assess.ItemIndex :=fieldbyname('Assess').AsInteger;
SqlText:=' Select sa_SaleInvoiceline.InvoiceNo,sa_SaleInvoiceline.ShipNo,sa_SaleInvoiceline.ShiplineNo,'
+' sa_SaleInvoiceline.ItemCode,ItemName, '
+' sa_SaleInvoiceline.ItemCode+'' ''+Item.ItemName as Itemflag, '
+' UomName, '
+' ShipQty, TaxPrice,TaxAmount,NoTaxPrice,NoTaxAmount, '
+' DiSCountRate,DiSCountAmount,sa_SaleInvoiceline.RemArk '
+' From sa_SaleInvoiceline '
+' Join Item '
+' On Item.ItemCode=sa_SaleInvoiceline.ItemCode '
+' Join Uom '
+' On Item.UomCode=Uom.UomCode'
+' where InvoiceNo= '''+fieldbyname('InvoiceNo').AsString+''' ' ;
AdoQry_Body.Close;
AdoQry_Body.SQL.Text:=SqlText;
AdoQry_Body.Open;
end ;
end;
procedure TFrm_Ar_Enter_PassSaleInvoice.Act_CheckExecute(Sender: TObject);
var
SqlText:String;
begin
inherited;
If (AdoQry_Head.Eof) And (AdoQry_Head.Bof) Then
Exit;
If Cx_Assess.ItemIndex = 0 then
If (DispInfo('确认要审核这张发票吗?',2)='y') Then
begin
try
Dbconnect.beginTrans ;
saveSalInvoiceHistory(dbconnect,edt_Invoiceno.Text,userCode,3);
SQlText:=' UpDate Sa_SaleInvoice Set Assess=1,assessdate= '+quotedstr(formatdatetime('yyyy.mm.dd',strtodatetime(GetServerDateTime(dbconnect))))+','
+' AssessorEmployeeCode='''+UserCode+''' Where InvoiceNo='''+Edt_InvoiceNo.Text+''' ';
AdoQry_Tmp.Close;
AdoQry_Tmp.sql.clear ;
AdoQry_Tmp.SQL.Text := SqlText;
AdoQry_Tmp.ExecSQL ;
// updateqty(0);
Cx_Assess.ItemIndex :=1;
Edt_AssessorEmployeeCode.Text := userCode;
Executesql(AdoQry_tmp,'select EmployeeName from Employee where EmployeeCode='+quotedstr(userCode),0);
edt_assessName.Text:=AdoQry_tmp.fieldbyname('EmployeeName').asstring;
AdoQry_Head.Edit;
AdoQry_Head.fieldbyname('Assess').AsInteger:=1;
AdoQry_Head.fieldbyname('AssessorEmployeeCode').AsString:=UserCode;
AdoQry_Head.fieldbyname('AssessName').AsString:=edt_assessName.Text;
AdoQry_Head.fieldbyname('assessflag').asstring:=UserCode+' '+ edt_assessName.Text;
AdoQry_Head.fieldbyname('assessdate').asstring:=formatdatetime('yyyy.mm.dd',strtodatetime(GetServerDateTime(dbconnect)));
AdoQry_Head.Post;
Dbconnect.CommitTrans;
DispInfo('审核发票'+edt_Invoiceno.Text+'成功!',3);
except
if dbconnect.InTransaction then
dbconnect.RollBackTrans;
end;
end;
end;
procedure TFrm_Ar_Enter_PassSaleInvoice.Act_CancelCheckExecute(
Sender: TObject);
var
SqlText:String;
begin
inherited;
{ If (AdoQry_Head.Eof) And (AdoQry_Head.Bof) Then
Exit;
If Cx_Assess.ItemIndex = 1 then
If (DispInfo('确认真的要取消审核这张销售发货单吗?',2)='y') Then
begin
Dbconnect.beginTrans ;
saveShipOrderHistory(dbconnect,edt_Shipno.text,userCode,4);
SQlText:=' UpDate Sa_ShipOrder Set Assess=0, '
+' AssessorEmployeeCode='''' Where ShipNo='''+Edt_ShipNo.Text+''' ';
AdoQry_Tmp.Close;
AdoQry_Tmp.sql.clear ;
AdoQry_Tmp.SQL.Text := SqlText;
AdoQry_Tmp.ExecSQL ;
updateqty(1);
AdoQry_Head.Edit;
AdoQry_Head.fieldbyname('Assess').AsInteger:=0;
AdoQry_Head.fieldbyname('AssessorEmployeeCode').AsString:='';
AdoQry_Head.Post;
Cx_Assess.ItemIndex :=0;
Edt_AssessorEmployeeCode.Text := '';
edt_assessName.Text:='' ;
Dbconnect.CommitTrans;
end; }
end;
function TFrm_Ar_Enter_PassSaleInvoice.enoughCurrentInv(whCode,WhPositionCode,ItemCode:string;qty:real):boolean;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='select onhandInv from CurrentInv '
+' where whCode='+quotedstr(whCode)
+' and WhPositionCode='+quotedstr(WhPositionCode)
+' and ItemCode='+quotedstr(ItemCode);
try
Executesql(AdoQry,sqltext,0);
if AdoQry.RecordCount>0 then
if AdoQry.fieldbyname('onhandInv').asfloat>=qty then
Result:=True;
finally
AdoQry.Free;
end;
end;
function TFrm_Ar_Enter_PassSaleInvoice.enoughBatchInv(Batchno,whCode,WhPositionCode:string;qty:real):boolean;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='select InvQty from BatchCurrentInv '
+' where whCode='+quotedstr(whCode)
+' and WhPositionCode='+quotedstr(WhPositionCode)
+' and Batchno='+quotedstr(Batchno);
try
Executesql(AdoQry,sqltext,0);
if AdoQry.RecordCount>0 then
if AdoQry.fieldbyname('InvQty').asfloat>=qty then
Result:=True;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Ar_Enter_PassSaleInvoice.updateslolineqty(slono:string;slolineno:integer;qty:real;Addorreduce:integer);
var AdoQry:TAdoQuery;
sqltext:string;
begin
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='update sa_SaleOrderline'
+' set Shipqty=Shipqty'+iifValue(Addorreduce=0,'+','-')+floattostr(qty)+','
+' PrepareShipqty=PrepareShipqty'+iifValue(Addorreduce=0,'-','+')+floattostr(qty)
+' where slono='+quotedstr(slono)
+' and slolineno='+inttostr(slolineno);
try
Executesql(AdoQry,sqltext,1);
finally
AdoQry.Free;
end;
end;
procedure TFrm_Ar_Enter_PassSaleInvoice.reduceItemqty(ItemCode:string;qty:real;Addorreduce:integer);
var AdoQry:TAdoQuery;
sqltext:string;
begin
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='update Item'
+' set CurrentonhandInv=CurrentonhandInv'+iifValue(Addorreduce=0,'+','-')+floattostr(qty)
+' where ItemCode='+quotedstr(ItemCode);
try
Executesql(AdoQry,sqltext,1);
finally
AdoQry.Free;
end;
end;
procedure TFrm_Ar_Enter_PassSaleInvoice.reduceCurrentInv(whCode,WhPositionCode,ItemCode:string;qty:real;Addorreduce:integer);
var AdoQry:TAdoQuery;
sqltext:string;
begin
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='update CurrentInv '
+' set onhandInv=onhandInv'+iifValue(Addorreduce=0,'+','-')+floattostr(qty)
+' where whCode='+quotedstr(whCode)
+' and WhPositionCode='+quotedstr(WhPositionCode)
+' and ItemCode='+quotedstr(ItemCode);
try
Executesql(AdoQry,sqltext,1);
finally
AdoQry.Free;
end;
end;
procedure TFrm_Ar_Enter_PassSaleInvoice.reduceBatchInv(Batchno,whCode,WhPositionCode:string;qty:real;Addorreduce:integer);
var AdoQry:TAdoQuery;
sqltext:string;
begin
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='update BatchCurrentInv '
+' set InvQty=InvQty'+iifValue(Addorreduce=0,'+','-')+floattostr(qty)
+' where Batchno='+quotedstr(Batchno)
+' and whCode='+quotedstr(whCode)
+' and WhPositionCode='+quotedstr(WhPositionCode);
try
Executesql(AdoQry,sqltext,1);
finally
AdoQry.Free;
end;
end;
procedure TFrm_Ar_Enter_PassSaleInvoice.updateqty(Addorreduce:integer);
var enoughBatch:boolean;
enoughCurrent:boolean;
Book:string;
begin
Book:=AdoQry_Body.BookmArk;
AdoQry_Body.First;
while not AdoQry_Body.Eof do
begin
enoughBatch:=enoughBatchInv(AdoQry_Body.fieldbyname('Batchno').asstring,AdoQry_Body.fieldbyname('whCode').asstring,AdoQry_Body.fieldbyname('WhPositionCode').asstring,AdoQry_Body.fieldbyname('Shipqty').asfloat);
enoughCurrent:=enoughCurrentInv(AdoQry_Body.fieldbyname('whCode').asstring,AdoQry_Body.fieldbyname('WhPositionCode').asstring,AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('Shipqty').asfloat);
if AdoQry_Body.fieldbyname('Batchno').asstring<>'' then
if (Addorreduce=0) and (not enoughBatch) then
begin
DispInfo('第'+inttostr(AdoQry_Body.recno)+'行'+quotedstr(AdoQry_Body.fieldbyname('ItemCode').asstring)+'物料'+AdoQry_Body.fieldbyname('whName').asstring+AdoQry_Body.fieldbyname('WhPositionName').asstring+'批次库存不够!',1);
abort;
end;
if (Addorreduce=0 ) and (not enoughCurrent) then
begin
DispInfo('第'+inttostr(AdoQry_Body.recno)+'行'+quotedstr(AdoQry_Body.fieldbyname('ItemCode').asstring)+'物料'+AdoQry_Body.fieldbyname('whName').asstring+AdoQry_Body.fieldbyname('WhPositionName').asstring+'库存不够!',1);
abort;
end;
if AdoQry_Body.fieldbyname('Batchno').asstring<>'' then
reduceBatchInv(AdoQry_Body.fieldbyname('Batchno').asstring,AdoQry_Body.fieldbyname('whCode').asstring,AdoQry_Body.fieldbyname('WhPositionCode').asstring,AdoQry_Body.fieldbyname('Shipqty').asfloat,1);
reduceCurrentInv(AdoQry_Body.fieldbyname('whCode').asstring,AdoQry_Body.fieldbyname('WhPositionCode').asstring,AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('Shipqty').asfloat,1);
reduceItemqty(AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('Shipqty').asfloat,1);
saveSaleOrderLineHistory(dbconnect,AdoQry_Body.fieldbyname('slono').asstring,AdoQry_Body.fieldbyname('slolineno').asinteger,userCode,1);
updateslolineqty(AdoQry_Body.fieldbyname('slono').asstring,AdoQry_Body.fieldbyname('slolineno').asinteger,AdoQry_Body.fieldbyname('Shipqty').asfloat,0);
AdoQry_Body.Next;
end;
AdoQry_Body.BookmArk:=Book;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -