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

📄 inv_salematerialaudit_b.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Inv_SaleMaterialAudit_B;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Check_Body, Db, ActnList, AdODB, Grids, DBGridEh, StdCtrls,
  ExtCtrls, ComCtrls, ToolWin, Mask, ExtEdit, DBGrids, jpeg;

Type
  TFrm_Inv_SaleMaterialAudit_B = Class(TFrm_Base_Check_Body)
    Label1: TLabel;
    Label2: TLabel;
    Label7: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Lbl_CustomerName: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Lbl_Warehouse: TLabel;
    Lbl_CustomerCode: TLabel;
    Lbl_InvBillNo: TLabel;
    Lbl_WhPosition: TLabel;
    Lbl_InvBillRemArk: TLabel;
    MEdt_InvBillDate: TMaskEdit;
    AdoQry_BodyInvBillLineNo: TStringField;
    AdoQry_BodyItemCode: TStringField;
    AdoQry_BodyItemName: TStringField;
    AdoQry_BodyUomName: TStringField;
    AdoQry_BodyInvBillQty: TFloatField;
    AdoQry_BodyInvBillSfcQty: TFloatField;
    AdoQry_BodyCurrentInvQty: TFloatField;
    AdoQry_BodyBillLineRemArk: TStringField;
    AdoQry_BodyBatchNo: TStringField;
    procedure Act_CheckExecute(Sender: TObject);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Act_autoExecute(Sender: TObject);
    procedure AdoQry_BodyInvBillQtyChange(Sender: TField);
    procedure AdoQry_BodyBeforeInsert(DataSet: TDataSet);
    procedure DateCheck(Sender: TObject);
    procedure DBGridEhKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure AdoQry_BodyBatchNoChange(Sender: TField);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure InitControls; Override;
  end;

var
  Frm_Inv_SaleMaterialAudit_B: TFrm_Inv_SaleMaterialAudit_B;

implementation

uses Sys_Global,Inv_Global;

{$R *.DFM}

{ TFrm_Inv_SaleMaterialAudit_B }

procedure TFrm_Inv_SaleMaterialAudit_B.InitControls;
var
  Bill_ID,InvFields:String;
begin
  inherited;
  InvFields:=GetInvField(AdoQry_Tmp,AdoQry_Head.fieldbyname('WHCode').AsString
    ,AdoQry_Head.fieldbyname('WhPositionCode').AsString,'CurrentInv');
  if(AdoQry_Head.fieldbyname('InvBillWHChck').AsInteger<>1)then
  begin
    Act_Check.Enabled:=True;
    MEdt_InvBillDate.Enabled:=True;
    Act_auto.Enabled:=True;
  end
  else
  begin
    Act_Check.Enabled:=False;
    MEdt_InvBillDate.Enabled:=False;
    Act_auto.Enabled:=False;
  end;
  Bill_ID:=AdoQry_Head.fieldbyname('InvBillId').AsString;

  AdoQry_Body.Close;
  AdoQry_Body.SQL.Text:='Select'
    +' InvOutBillLine.InvBillLineNo'
    +',InvOutBillLine.ItemCode'
    +',Item.ItemName'
    +',Uom.UomName'
    +',InvOutBillLine.InvBillQty'
    +',InvOutBillLine.BatchNo'
    +',InvOutBillLine.InvBillSfcQty'
    +',InvOutBillLine.BillLineRemArk'
    +',CurrentInv.'+InvFields+' As CurrentInvQty'
    +' From InvOutBillLine'
    +' Join Item On InvOutBillLine.ItemCode=Item.ItemCode'
    +' Join Uom On Item.UomCode=Uom.UomCode'
    +' Left Join CurrentInv On InvOutBillLine.ItemCode=CurrentInv.ItemCode'
    +' And CurrentInv.WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
    +' And CurrentInv.WhPositionCode='''+AdoQry_Head.fieldbyname('WhPositionCode').AsString+''''
    +' Where InvOutBillLine.InvBillId='+Bill_ID+'';
  AdoQry_Body.Open;
  AdoQry_Body.Sort:='InvBillLineNo';

  if(AdoQry_Head.fieldbyname('InvBillWHChck').AsInteger<>1)then
  begin
    AdoQry_Body.Last;
    while not AdoQry_Body.Bof do
    begin
      AdoQry_Body.Edit;
      if AdoQry_Body.fieldbyname('InvBillQty').AsFloat<0 then
        Act_auto.Enabled:=False;
      AdoQry_Body.fieldbyname('InvBillQty').Asstring:='0';
      AdoQry_Body.Post;
      AdoQry_Body.Prior;
    end;
  end;

  with AdoQry_Head do
  begin
    Lbl_CustomerCode.Caption:=fieldbyname('CustomerCode').AsString;
    Lbl_CustomerName.Caption:=fieldbyname('CustomerName').AsString;
    Lbl_InvBillNo.Caption:=fieldbyname('InvBillNo').AsString;
    MEdt_InvBillDate.Text:=fieldbyname('InvBillDate').AsString;
    Lbl_InvBillRemArk.Caption:=fieldbyname('InvBillRemArk').AsString;
    Lbl_Warehouse.Caption:=fieldbyname('WHCodeName').AsString;
    Lbl_WhPosition.Caption:=fieldbyname('WhPositionCodeName').AsString;
  end;
end;

procedure TFrm_Inv_SaleMaterialAudit_B.Act_CheckExecute(Sender: TObject);
var
  Bill_Count,DispString,Tempstr:String;
  PriceType:Integer;
  NeedChangePrice:Boolean;
begin
  inherited;
  DateCheck(MEdt_InvBillDate);
  DBGridEh.SetFocus;
  if AdoQry_Body.State in [dsEdit] then
    AdoQry_Body.Post;
  DispString:=' 单据核定失败,请稍后再试 ';
  DBConnect.beginTrans;

  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.Text:='Select PriceType From Warehouse'
    +' Where WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+'''';
  AdoQry_Tmp.Open;
  PriceType:=AdoQry_Tmp.fieldbyname('PriceType').AsInteger;
  AdoQry_Tmp.Close;

  NeedChangePrice:=NeedChangeAveragePrice(AdoQry_Tmp,FormatDateTime('yyyy.mm',
    AdoQry_Head.fieldbyname('InvBillDate').AsDateTime));
  try
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.Text:='Update InvOutBill Set '
      +' InvBillWHChck='+'1'+''
      +',WH_EmployeeCode='''+UserCode+''''
      +',InvBillDate='''+MEdt_InvBillDate.Text+''''
      +',InvBillMonth='''+Copy(MEdt_InvBillDate.Text,1,7)+''''
      +' Where InvBillId='+AdoQry_Head.fieldbyname('InvBillId').AsString+'';
    AdoQry_Tmp.ExecSQL;
    //设置库存变动标志
    ChangeInvStatus(AdoQry_Tmp,AdoQry_Head.fieldbyname('WHCode').AsString,
      FormatDateTime('yy.mm',AdoQry_Head.fieldbyname('InvBillDate').AsDateTime));

    AdoQry_Body.First;
    while(not AdoQry_Body.Eof)do
    begin
      if BatchCtrl(AdoQry_Tmp,AdoQry_Body.fieldbyname('ItemCode').AsString)
        and(AdoQry_Body.fieldbyname('BatchNo').AsString='') then
      begin
        DispString:='请录入批次号';
        Abort;
      end;
      if (AdoQry_Body.fieldbyname('BatchNo').AsString<>'') then
      begin
        if not BatchCtrl(AdoQry_Tmp,AdoQry_Body.fieldbyname('ItemCode').AsString)then
        begin
          DispString:='该物料不受批次控制,不能录入批次号';
          Abort;
        end;
        if not BatchNoCheck(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
          AdoQry_Body.fieldbyname('ItemCode').AsString,'',MEdt_InvBillDate.Text) then
          Abort;
      end;
      //如果当前仓库计价方式是移动加权,且此刻可更新移动加权时
      if (PriceType=0)then
      begin
        if(True)then
        begin
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:='If Not Exists'
            +' (Select ItemCode'
            +'  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+''''
            +')';
          AdoQry_Tmp.ExecSQL;
          {单据保存,更改移动加权平均价:如果ApQty<>0,则使用原来的算法
          否则ApQty=ApQty-(出库数)ApAmount=ApAmount-出库数量*AveragePrice
          AveragePrice保持不变}
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:='Update AveragePrice Set'
            +' ApAmount=ApAmount-(Case When ApQty=0 Then AveragePrice'
            +' Else ApAmount/ApQty end)*('+AdoQry_Body.fieldbyname('InvBillQty').AsString+')'
            +' Where WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
            +' And ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''';
          AdoQry_Tmp.ExecSQL;

          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:='Update AveragePrice Set'
            +' ApQty=ApQty-('+AdoQry_Body.fieldbyname('InvBillQty').AsString+') '
            +' Where WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
            +' And ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -