📄 inv_saleproduct_b.pas
字号:
unit Inv_SaleProduct_B;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Entry_Body, Db, ActnList, AdODB, Grids, DBGridEh, ExtCtrls,
ComCtrls, ToolWin, StdCtrls, Mask, ExtEdit, DBCtrls, ExtPrintReport;
Type
TFrm_Inv_SaleProduct_B = Class(TFrm_Base_Entry_Body)
Label1: TLabel;
CmBx_Warehouse: TComboBox;
Label2: TLabel;
CmBx_WhPosition: TComboBox;
Label3: TLabel;
Label4: TLabel;
ExtEdt_CustomerCode: TExtEdit;
Lbl_CustomerName: TLabel;
Label7: TLabel;
Edt_InvBillNo: TEdit;
Label8: TLabel;
MEdt_InvBillDate: TMaskEdit;
Label9: TLabel;
Edt_InvBillRemArk: TEdit;
Label10: TLabel;
DBText1: TDBText;
Lbl_InvBillTaxRate: TLabel;
Label5: TLabel;
procedure FormCreate(Sender: TObject);
procedure MEdt_InvBillDateExit(Sender: TObject);
procedure CmBx_WarehouseChange(Sender: TObject);
procedure Act_PreviewExecute(Sender: TObject);
procedure Act_PrintExecute(Sender:Tobject);
procedure CustomerCodeCheck(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure SetStatus(CurrentStatus:String;var AnswerStatus,
EnableControls:String); Override;
procedure InitControls; Override;
procedure SaveHeadData; Override;
procedure SaveData; Override;
end;
var
Frm_Inv_SaleProduct_B: TFrm_Inv_SaleProduct_B;
implementation
uses Sys_Global,Inv_SaleProduct_D,Inv_Global;
{$R *.DFM}
{ TFrm_Inv_SaleMaterial_B }
procedure TFrm_Inv_SaleProduct_B.InitControls;
var
Bill_ID:String;
begin//初始化Form上的控件
SetFocus_Control:=CmBx_Warehouse;
if Param2='NoMps' then
begin
FormCaption:='非主计划销售发货单制单';
DBGridEh.Columns[3].Visible:=False;
end
else
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select MrpParamValueN From MrpParam'
+' Where MrpParamCode=''autoBalanceMps''';
AdoQry_Tmp.Open;
if (AdoQry_Tmp.fieldbyname('MrpParamValueN').AsString='1') then
DBGridEh.Columns[3].Visible:=False;
FormCaption:='主计划销售发货单制单';
end;
inherited;
InitUsableWHCmBx(AdoQry_Tmp,UserCode,CmBx_Warehouse,False);
//取得单据号
if Status<>'Add' then
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select InvBillId From InvOutBill'
+' Where InvBillNo='''+AdoQry_Head.fieldbyname('InvBillNo').AsString+''''
+' And WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+'''';
AdoQry_Tmp.Open;
Bill_ID:=AdoQry_Tmp.fieldbyname('InvBillId').AsString;
end
else
Bill_ID:='-1';
//设置表体AdoQry_Body 当前SQL语句(注意要能与表头关联)
AmountFields:='InvBillSaleAmount,InvBillNoTaxSaleAmount,';
PriceFields:='InvBillSalePrice,InvBillNoTaxSalePrice,';
AdoQry_Body.Close;
AdoQry_Body.SQL.Text:='Select '
+'InvOutBillLine.InvBillLineNo'
+',InvOutBillLine.ItemCode'
+',InvOutBillLine.MpsId'
+',Item.ItemName'
+',Uom.UomName'
+',InvOutBillLine.InvBillQty'
+',InvOutBillLine.BatchNo'
+',RealSalePrice.InvBillSalePrice'
+',RealSalePrice.InvBillSaleAmount'
+',RealSalePrice.InvBillNoTaxSalePrice'
+',RealSalePrice.InvBillNoTaxSaleAmount'
+',InvOutBillLine.BillLineRemArk'
+' From InvOutBillLine'
+' Join Item On InvOutBillLine.ItemCode=Item.ItemCode'
+' Join Uom On Item.UomCode=Uom.UomCode'
+',RealSalePrice'
+' Where InvOutBillLine.InvBillId=RealSalePrice.InvBillId'
+' and InvOutBillLine.InvBillLineNo=RealSalePrice.InvBillLineNo'
+' and InvOutBillLine.InvBillId='+Bill_ID+'';
AdoQry_Body.Open;
with AdoQry_Head do
begin
InitCmBxText(CmBx_Warehouse,fieldbyname('WHCode').AsString);
CmBx_Warehouse.OnChange(CmBx_Warehouse);
if Status<>'Add' then
begin
Edt_InvBillNo.Text:=fieldbyname('InvBillNo').AsString;
MEdt_InvBillDate.Text:=fieldbyname('InvBillDate').AsString;
end
else
begin
Edt_InvBillNo.Text:='';
MEdt_InvBillDate.Text:=FormatDateTime('yyyy.mm.dd',Now);
end;
Lbl_InvBillTaxRate.Caption:=fieldbyname('InvBillTaxRate').AsString;
ExtEdt_CustomerCode.Text:=fieldbyname('CustomerCode').AsString;
Lbl_CustomerName.Caption:=fieldbyname('CustomerName').AsString;
Edt_InvBillRemArk.Text:=fieldbyname('InvBillRemArk').AsString;
end;
end;
procedure TFrm_Inv_SaleProduct_B.SaveData;
var
Bill_No,Bill_Id,DispString,MpsId:String;
Bill_LineNo:Integer;
begin
inherited;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select MrpParamValueN From MrpParam'
+' Where MrpParamCode=''autoBalanceMps''';
AdoQry_Tmp.Open;
if (AdoQry_Tmp.fieldbyname('MrpParamValueN').AsString='1')
or(Param2='NoMps') then
MpsId:='False'
else
MpsId:='True';
DispString:=' 单据保存失败,请稍后再试 ';
DBConnect.beginTrans;
try
if(Status='Add')then
begin
if AdoQry_Body.RecordCount=0 then
begin
DispString:=' 新增的单据没有记录,不允许保存 ';
Abort;
end;
Bill_No:=GetNo(DBConnect,AdoQry_Head.fieldbyname('WHCode').AsString+'C'+
FormatDateTime('yymm',AdoQry_Head.fieldbyname('InvBillDate').AsDateTime),'InvBill');
AdoQry_Head.fieldbyname('InvBillNo').AsString:=Bill_No;
AdoQry_Tmp.Close;
if Param2<>'NoMps' then
begin
AdoQry_Tmp.SQL.Text:='Insert InvOutBill'+
'(InvBillNo,WHCode,InvBillTaxRate,InvBillDate,CustomerCode,'+
'WhPositionCode,InvBillMonth,BillTypeCode,EmployeeCode,Sal_EmployeeCode,InvBillRemArk)'+
'Values('
+''''+Bill_No+''''
+','''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
+','+AdoQry_Head.fieldbyname('InvBillTaxRate').AsString+''
+','''+AdoQry_Head.fieldbyname('InvBillDate').AsString+''''
+','''+AdoQry_Head.fieldbyname('CustomerCode').AsString+''''
+','''+AdoQry_Head.fieldbyname('WhPositionCode').AsString+''''
+','''+FormatDateTime('yyyy.mm',AdoQry_Head.fieldbyname('InvBillDate').AsDateTime)+''''
+','''+Param1+''''
+','''+UserCode+''''
+','''+UserCode+''''
+','''+AdoQry_Head.fieldbyname('InvBillRemArk').AsString+''''
+')';
end
else
begin
AdoQry_Tmp.SQL.Text:='Insert InvOutBill'+
'(InvBillNo,WHCode,InvBillTaxRate,InvBillDate,CustomerCode,'+
'WhPositionCode,InvBillMonth,BillTypeCode,EmployeeCode,Sal_EmployeeCode'
+',InvBillRemArk,MpsSale)'
+' Values('
+' '''+Bill_No+''''
+','''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
+','+AdoQry_Head.fieldbyname('InvBillTaxRate').AsString+''
+','''+AdoQry_Head.fieldbyname('InvBillDate').AsString+''''
+','''+AdoQry_Head.fieldbyname('CustomerCode').AsString+''''
+','''+AdoQry_Head.fieldbyname('WhPositionCode').AsString+''''
+','''+FormatDateTime('yyyy.mm',AdoQry_Head.fieldbyname('InvBillDate').AsDateTime)+''''
+','''+Param1+''''
+','''+UserCode+''''
+','''+UserCode+''''
+','''+AdoQry_Head.fieldbyname('InvBillRemArk').AsString+''''
+',0'
+')'
end;
AdoQry_Tmp.ExecSQL;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select @@identity as Bill_Id';
AdoQry_Tmp.Open;
Bill_Id:=AdoQry_Tmp.fieldbyname('Bill_Id').AsString;
end;
ChangeInvStatus(AdoQry_Tmp,AdoQry_Head.fieldbyname('WHCode').AsString,
FormatDateTime('yy.mm',AdoQry_Head.fieldbyname('InvBillDate').AsDateTime));
AdoQry_Body.First;
Bill_LineNo:=1;
while(not AdoQry_Body.Eof)do
begin
AdoQry_Tmp.Close;
if MpsId='True' then
AdoQry_Tmp.SQL.Text:='Insert InvOutBillLine'
+'(InvBillId,InvBillLineNo,ItemCode,InvBillQty,InvBillSfcQty,MpsId'
+',BillLineRemArk,BatchNo)'
+' Values('
+' '''+Bill_Id+''''
+','+IntToStr(Bill_LineNo)+''
+','''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''
+','+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
+','+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
+','+AdoQry_Body.fieldbyname('MpsId').AsString+''
+','''+AdoQry_Body.fieldbyname('BillLineRemArk').AsString+''''
+','''+AdoQry_Body.fieldbyname('BatchNo').AsString+''''
+')'
else
AdoQry_Tmp.SQL.Text:='Insert InvOutBillLine'
+'(InvBillId,InvBillLineNo,ItemCode,InvBillQty,InvBillSfcQty'
+',BillLineRemArk,BatchNo)'
+' Values('
+''''+Bill_Id+''''
+','+IntToStr(Bill_LineNo)+''
+','''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''
+','+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
+','+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
+','''+AdoQry_Body.fieldbyname('BillLineRemArk').AsString+''''
+','''+AdoQry_Body.fieldbyname('BatchNo').AsString+''''
+')';
AdoQry_Tmp.ExecSQL;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Insert RealSalePrice'+
'(InvBillId,InvBillLineNo,InvBillSalePrice,InvBillSaleAmount,'+
'InvBillNoTaxSalePrice,InvBillNoTaxSaleAmount)'+
'Values('
+''''+Bill_Id+''''
+','+IntToStr(Bill_LineNo)+''
+','+AdoQry_Body.fieldbyname('InvBillSalePrice').AsString+''
+','+AdoQry_Body.fieldbyname('InvBillSaleAmount').AsString+''
+','+AdoQry_Body.fieldbyname('InvBillNoTaxSalePrice').AsString+''
+','+AdoQry_Body.fieldbyname('InvBillNoTaxSaleAmount').AsString+''
+')';
AdoQry_Tmp.ExecSQL;
if MpsId='True' then
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Update Mps Set'
+' MpsOutQty=MpsOutQty+'+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
+' Where MpsId='+AdoQry_Body.fieldbyname('MpsId').AsString+'';
AdoQry_Tmp.ExecSQL;
end;
AdoQry_Body.Next;
Bill_LineNo:=Bill_LineNo+1;
end;
DBConnect.CommitTrans;
except
DBConnect.RollBackTrans;
DispInfo(DispString,3);
Abort;
end;
end;
procedure TFrm_Inv_SaleProduct_B.SaveHeadData;
begin//把表头控件写入缓存,没Post
inherited;
with AdoQry_Head do
begin//把根据表头当前数据初始化,表头控件
fieldbyname('WHCode').AsString:=GetCode(CmBx_Warehouse.Text);
fieldbyname('WHName').AsString:=GetName(CmBx_Warehouse.Text);
fieldbyname('InvBillTaxRate').AsString:=Lbl_InvBillTaxRate.Caption;
fieldbyname('CustomerCode').AsString:=ExtEdt_CustomerCode.Text;
fieldbyname('CustomerName').AsString:=Lbl_CustomerName.Caption;
fieldbyname('InvBillDate').AsString:=MEdt_InvBillDate.Text;
fieldbyname('InvBillRemArk').AsString:=Edt_InvBillRemArk.Text;
fieldbyname('WhPositionCode').AsString:=GetCode(CmBx_WhPosition.Text);
fieldbyname('WhPositionName').AsString:=GetName(CmBx_WhPosition.Text);
end;
end;
procedure TFrm_Inv_SaleProduct_B.SetStatus(CurrentStatus: String;
var AnswerStatus, EnableControls: String);
begin//窗体状态设置
inherited;
if (CurrentStatus='Edit') then
begin
AnswerStatus:='ReadOnly';
end
else if (CurrentStatus='Add') then
begin
AnswerStatus:='Add';
EnableControls:='Edt_InvBillRemArk,';
end;
end;
procedure TFrm_Inv_SaleProduct_B.FormCreate(Sender: TObject);
begin
inherited;
Frm_Entry_Detail:=TFrm_Inv_SaleProduct_D.Create(Self);
CmBx_Warehouse.OnChange:=CmBx_WarehouseChange;
end;
procedure TFrm_Inv_SaleProduct_B.MEdt_InvBillDateExit(Sender: TObject);
begin//日期检查
inherited;
if(ActiveControl.Name='btn_Cancel')then
Exit;
DateCheck(Sender);
if WHClsPeriodCheck(AdoQry_Tmp,GetCode(CmBx_Warehouse.Text),
Copy(TEdit(Sender).Text,1,7))=False then
begin
TWinControl(Sender).SetFocus;
Abort;
end;
end;
procedure TFrm_Inv_SaleProduct_B.CmBx_WarehouseChange(Sender: TObject);
begin//货位设置
inherited;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select WhPosition.WhPositionCode'
+'+'' ''+WhPosition.WhPositionName As WhPositionCodeName'
+' From WhPosition'
+' Where WhPosition.WHCode='''+GetCode(CmBx_Warehouse.Text)+''''
+' And WhPosition.WhPositionType<>1';
AdoQry_Tmp.Open;
AdoQry_Tmp.First;
CmBx_WhPosition.clear;
while not AdoQry_Tmp.Eof do
begin
CmBx_WhPosition.Items.Add(AdoQry_Tmp.fieldbyname('WhPositionCodeName').AsString);
AdoQry_Tmp.Next;
end;
InitCmBxText(CmBx_WhPosition,AdoQry_Head.fieldbyname('WhPositionCode').AsString);
end;
procedure TFrm_Inv_SaleProduct_B. Act_PrintExecute(Sender: TObject);
begin
// inherited;
BillPrint(AdoQry_Tmp.Connection,GetCode(CmBx_Warehouse.text),Edt_InvBillNo.text,Param1,ModuleCode,False,False,True,'');
end;
procedure TFrm_Inv_SaleProduct_B.Act_PreviewExecute(Sender: TObject);
begin
// inherited;
BillPrint(AdoQry_Tmp.Connection,GetCode(CmBx_Warehouse.text),Edt_InvBillNo.text,Param1,ModuleCode,True,False,True,'');
end;
procedure TFrm_Inv_SaleProduct_B.CustomerCodeCheck(Sender: TObject);
begin//税率设置
inherited;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select CustomerTaxRate_Percent From Customer'
+' Where CustomerCode='''+TEdit(Sender).Text+'''';
AdoQry_Tmp.Open;
Lbl_InvBillTaxRate.Caption:=AdoQry_Tmp.fieldbyname('CustomerTaxRate_Percent').AsString;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -