⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inv_salematerial_b.pas

📁 一个MRPII系统源代码版本
💻 PAS
字号:
unit Inv_SaleMaterial_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_SaleMaterial_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_SaleMaterial_B: TFrm_Inv_SaleMaterial_B;

implementation

uses Sys_Global,Inv_SaleMaterial_D,Inv_Global;

{$R *.DFM}

{ TFrm_Inv_SaleMaterial_B }

procedure TFrm_Inv_SaleMaterial_B.InitControls;
var
  Bill_ID:String;
begin//初始化Form上的控件
  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'
    +',Item.ItemName'
    +',Uom.UomName'
    +',InvOutBillLine.InvBillQty'
    +',InvOutBillLine.BatchNo'
    +',RealSalePrice.InvBillSalePrice'
    +',RealSalePrice.InvBillSaleAmount'
    +',RealSalePrice.InvBillNoTaxSalePrice'
    +',RealSalePrice.InvBillNoTaxSaleAmount'
    +',InvOutBillLine.BillLineRemArk'
    +',InvOutBillLine.TmpField'
    +' 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;
  AdoQry_Body.Sort:='InvBillLineNo';
  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_SaleMaterial_B.SaveData;
var
  Bill_No,Bill_Id,DispString:String;
  PriceType,Bill_LineNo:Integer;
begin
  inherited;
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.Text:='Select PriceType From Warehouse'
    +' Where WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+'''';
  AdoQry_Tmp.Open;
  if AdoQry_Tmp.fieldbyname('PriceType').AsString='0' then
    PriceType:=0
  else
    PriceType:=1;

  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;
      if AdoQry_Head.fieldbyname('InvBillTAXRATE').AsString='' then
      begin
        AdoQry_Head.Edit;
        AdoQry_Head.fieldbyname('InvBillTAXRATE').AsString:='0';
        AdoQry_Head.Post;
      end;
      AdoQry_Tmp.Close;
      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+''''
        +')';
      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
      if AdoQry_Body.fieldbyname('TmpField').AsString='' then
      begin
        AdoQry_Body.Edit;
        AdoQry_Body.fieldbyname('TmpField').AsString:='0';
        AdoQry_Body.Post;
      end;
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:='Insert InvOutBillLine'
        +'(InvBillId,InvBillLineNo,ItemCode,InvBillQty,InvBillSfcQty,BillLineRemArk'
        +',TmpField,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('TmpField').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;
      AdoQry_tmp.Close;
      if(PriceType=0)and(AdoQry_Body.fieldbyname('InvBillQty').AsFloat<0) then
      begin
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:='If Not Exists'
          +' (Select ApQty'
          +'  From AveragePrice'
          +'  Where WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
          +'  And ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+''')'
          +' Insert AveragePrice(WHCode,ItemCode)'
          +' Values('
          +' '''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
          +','''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''
          +')'

          +' Update AveragePrice Set'
          +' AveragePrice=+'+AdoQry_Body.fieldbyname('TmpField').AsString+''
          +' Where WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
          +' And ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''';
        AdoQry_Tmp.ExecSQL;
      end;

      AdoQry_Body.Next;
      Bill_LineNo:=Bill_LineNo+1;
    end;
    DBConnect.CommitTrans;
  except
    on e:Exception do
    begin
      DBConnect.RollBackTrans;
      RecOrderror(Self,AdoQry_tmp,E.message);
      DispInfo(DispString,3);
      Abort;
    end;
  end;
end;

procedure TFrm_Inv_SaleMaterial_B.SaveHeadData;
begin
  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('InvBillNo').AsString:=Edt_InvBillNo.Text;
    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_SaleMaterial_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_SaleMaterial_B.FormCreate(Sender: TObject);
begin
  inherited;
  Frm_Entry_Detail:=TFrm_Inv_SaleMaterial_D.Create(Self);
  SetFocus_Control:=CmBx_Warehouse;
  //CmBx_Warehouse.OnChange:=CmBx_WarehouseChange;
end;

procedure TFrm_Inv_SaleMaterial_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_SaleMaterial_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'
    +' And WhPosition.BackFlushWHP<>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_SaleMaterial_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_SaleMaterial_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_SaleMaterial_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 + -