inv_priceaudit_b.pas

来自「一个MRPII系统源代码版本」· PAS 代码 · 共 1,055 行 · 第 1/3 页

PAS
1,055
字号
unit Inv_PriceAudit_B;

Interface

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

Type
  TFrm_Inv_PriceAudit_B = Class(TFrm_Base_Entry_Body)
    Label1: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Label10: TLabel;
    Extedt_Billno: TExtEdit;
    Label3: TLabel;
    DBText1: TDBText;
    lbl_WhCode: TLabel;
    lbl_WhPositionCode: TLabel;
    Label6: TLabel;
    Label2: TLabel;
    lbl_Pono: TLabel;
    Label9: TLabel;
    lbl_Vendor: TLabel;
    Label12: TLabel;
    lbl_Currency: TLabel;
    Extedt_InvBilltaxrate: TExtEdit;
    Label7: TLabel;
    Label11: TLabel;
    Label13: TLabel;
    AdoQry_Bodypolineno: TIntegerField;
    AdoQry_BodyInvBillid: TBCDField;
    AdoQry_BodyInvBilllineno: TStringField;
    AdoQry_BodyInvBillqty: TFloatField;
    AdoQry_BodyItemCode: TStringField;
    AdoQry_BodyItemName: TStringField;
    AdoQry_BodyUomName: TStringField;
    AdoQry_BodyInvBillPrice: TFloatField;
    AdoQry_BodyInvBillAmount: TBCDField;
    AdoQry_BodyInvBillnotaxPrice: TFloatField;
    AdoQry_BodyInvBillnotaxAmount: TBCDField;
    lbl_BillTypeCode: TLabel;
    AdoQry_BodyValuation: TIntegerField;
    AdoQry_BodyBilllineremArk: TStringField;
    lbl_Month: TLabel;
    edt_Date: TEdit;
    Extedt_memo: TExtEdit;
    chck_realPrice: TCheckBox;
    Label14: TLabel;
    edt_memo1: TEdit;
    lbl_VendorBillno: TLabel;
    Label16: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Act_SaveExecute(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
    procedure edt_DateExit(Sender: TObject);
    procedure Act_ModifyExecute(Sender: TObject);
    procedure DBGridEhDblClick(Sender: TObject);
  private

    BillTypeCode:string;
    fExchRate,foldExchRate:string;
    fneednewBill:boolean;
    oldmemo,tmp_Date,oldInvBilltaxrate:string;
    modal:string;
    { Private declarations }
  public
    Bill_id:string;
    procedure InitControls;Override;
    procedure SaveHeadData;Override;
    procedure SaveData; Override;//把表头控件写入缓存,不要Post
    procedure SetStatus(CurrentStatus:String;var AnswerStatus,
  EnableControls:String);Override;
    { Public declarations }
  end;

var
  Frm_Inv_PriceAudit_B: TFrm_Inv_PriceAudit_B;

implementation

uses Sys_Global,Inv_Global,Inv_PriceAudit_D, Inv_PurchaseIn_P_CC,Inv_PurchaseIn_P_OO,
  Inv_PriceAudit_H;
{$R *.DFM}

procedure TFrm_Inv_PriceAudit_B.InitControls;
var
  body_Sqltext:string;
  chck_Month,Current_Date,tmp_Head_Date:string;
begin
  //初始化Form上的控件
  //为了控制基类保存后会刷新DBGRID,所以用了基类中的一个大状态参数
  //该参数为True表示,表示只显示当前数据,False表示从Head中第一次
  //进入BODY窗体

  //这两个参数是回传到基类后控制价格及金额的显示格式
  AmountFields:='InvBillnotaxAmount,InvBillAmount,';
  PriceFields:='InvBillnotaxPrice,InvBillPrice,';
  if showflag=True then
    exit;
  //单据类型
  BillTypeCode:=AdoQry_Head.fieldbyname('BillTypeCode').AsString ;
  //菜单传入来的参数‘暂估价’‘核价’
  modal:=Param1;

  Bill_ID:=AdoQry_Head.fieldbyname('InvBillid').AsString ;
  edt_memo1.Text:=AdoQry_Head.fieldbyname('InvBillremArk').AsString ;
    //如果不是进口‘0102’ 取不是进口的单价,金额,否则取进口单价,金额
  if BillTypeCode<>'0102' then
     body_Sqltext:='select bl.InvBillid,'+
                 'bl.InvBilllineno,'+
                 'bl.pono,'+
                 'bl.polineno,'+
                 'bl.InvBillqty,'+
                 'bl.ItemCode,'+
                 'bl.BilllineremArk,'+
                 'i.ItemName,'+
                 'u.UomName,'+
                 'bl.InvBillPrice,'+
                 'bl.InvBillAmount,'+
                 'bl.InvBillnotaxPrice,'+
                 'bl.InvBillnotaxAmount, '+
                 'bl.Valuation '+
          ' from InvInBillline bl'+
          '  left join Item i on bl.ItemCode=i.ItemCode '+
          '  left join Uom u on i.UomCode=u.UomCode '+
          ' where bl.InvBillid='+Bill_id+
          ' Order by bl.InvBillid,bl.InvBilllineno,bl.ItemCode '
  else
    body_Sqltext:='select bl.InvBillid,'+
                 'bl.InvBilllineno,'+
                 'bl.pono,'+
                 'bl.polineno,'+
                 'bl.InvBillqty,'+
                 'bl.ItemCode,'+
                 'bl.BilllineremArk,'+
                 'i.ItemName,'+
                 'u.UomName,'+
                 'bl.InvBillPricec as InvBillPrice,'+
                 'bl.InvBillAmountc as InvBillAmount,'+
                 'bl.InvBillnotaxPricec as InvBillnotaxPrice,'+
                 'bl.InvBillnotaxAmountc as InvBillnotaxAmount, '+
                 'bl.Valuation '+
          ' from InvInBillline bl'+
          '  left join Item i on bl.ItemCode=i.ItemCode '+
          '  left join Uom u on i.UomCode=u.UomCode '+
          ' where bl.InvBillid='+Bill_id+
          ' Order by bl.InvBillid,bl.InvBilllineno,bl.ItemCode ';


  with AdoQry_Body do
  begin
    Close;
    sql.clear;
    sql.Add(body_Sqltext);
    open;
  end;
  //己结帐的下一个月份
  //tmp_Date己结帐的下一个月份
  //   如果单据月份<=结帐月份+1个月,则=结帐月份+1个月
 //否则单据月份=单据月份
 //获得服务器日期,即当前日期
 //如果单据月份<当前月份,则单据日期=单据月份的最后一天
 //否则单据日期=当前日期
  DateSeparator:='.';
  Shortdateformat:='yyyy.mm.dd';
  //系统结帐月份
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.text:=
      ' select left(convert(varchAr,Invstatus),7) as InvStatus '+
      '  from Invstatus '+
      ' where InvStatusName=''clsperiod'' ';
    open;
    tmp_Date:=datetostr(incMonth(strtodatetime(Trim(fieldbyname('Invstatus').asstring)+'.01'),2)-1);
  end;
  //单据头日期
  tmp_Head_Date:=Trim(AdoQry_Head.fieldbyname('InvBilldate').asstring);
  if copy(tmp_Head_Date,1,7)<=copy(tmp_Date,1,7) then
     chck_Month:=copy(tmp_Date,1,7)
  else
     chck_Month:=copy(tmp_Head_Date,1,7);
  //取服务器时间作为当前时间
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select convert(varchAr(10),getdate(),102) as Currentdate ');
    open;
    Current_Date:=fieldbyname('Currentdate').asstring;
  end;
  if chck_Month<copy(Current_Date,1,7) then
     Current_Date:=chck_Month+copy(datetostr(incMonth(strtodate(chck_Month+'.01'),1)-1),8,3)
  else
     Current_Date:=chck_Month+copy(Current_Date,8,3);

   lbl_Month.Caption:=chck_Month+'.';
   edt_Date.text:=copy(Current_Date,9,2);

  with AdoQry_Head do
  begin
    lbl_WhCode.Caption:=fieldbyname('whCodeName').asstring;
    lbl_WhPositionCode.Caption:=fieldbyname('WhPositionCodeName').asstring;
    lbl_Vendor.Caption:=fieldbyname('VendorCode').asstring+' '+fieldbyname('VendorName').asstring;
    lbl_Pono.Caption:=fieldbyname('pono').asstring;
    Extedt_memo.text:='';//fieldbyname('InvBillremArk').asstring;
    oldmemo:=Trim(fieldbyname('InvBillremArk').asstring);
    Extedt_Billno.text:=fieldbyname('InvBillno').asstring;
    Extedt_InvBilltaxrate.text:=fieldbyname('InvBilltaxrate').asstring;
    oldInvBilltaxrate:=fieldbyname('InvBilltaxrate').asstring;
    lbl_BillTypeCode.Caption:=fieldbyname('BillTypeName').asstring;
    lbl_VendorBillno.Caption:=fieldbyname('VendorBillno').asstring;
   //下面两个参数于返Head时定位
    if status<>'ReadOnly' then
    begin
      Frm_Inv_PriceAudit_H.lct_WhCodeName:=fieldbyname('whCodeName').asstring;
      Frm_Inv_PriceAudit_H.lct_InvBillno:=fieldbyname('InvBillno').asstring;
    end;
    //如果是进口采购,则从EXCHArATE中取入库时间的汇率
    if BillTypeCode='0102' then
    begin
      if AdoQry_Head.fieldbyname('currencyCode').asstring<>'00' then
      begin
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.clear;
        AdoQry_tmp.sql.Add('select ExchRate '+
                  ' from ExchRate '+
                  'where exchMonth='''+copy(fieldbyname('InvBilldate').asstring,1,7)+''' and '+
                  '      currencyCode='''+AdoQry_Head.fieldbyname('currencyCode').asstring+'''');
        AdoQry_tmp.open;
        foldExchRate:=AdoQry_tmp.fieldbyname('ExchRate').asstring;
      end
      else foldExchRate:='1';
    end;

    lbl_Currency.Caption:=AdoQry_Head.fieldbyname('currencyCode').asstring+' '+AdoQry_Head.fieldbyname('currencyName').asstring;
    fExchRate:='1';
  end;
  inherited;
end;


procedure TFrm_Inv_PriceAudit_B.SetStatus(CurrentStatus:String;var AnswerStatus,
  EnableControls:String);
begin//指明当前状态,定义Enable=True的控件
  inherited;
  if AdoQry_Head.fieldbyname('RealBillFlag').Value=0 then
  begin
    status:='ReadOnly';
  end;
  if status='ReadOnly' then
  begin
    AnswerStatus:='ReadOnly';
    EnableControls:='';
  end
  else
  begin
    AnswerStatus:='AllEdit';
    //当单据体有数据时,单据头Enable=True 的控件
    EnableControls:='edt_Date,Extedt_memo,chck_realPrice,';
  end;
end;

procedure TFrm_Inv_PriceAudit_B.SaveHeadData;
begin
  inherited;
  AdoQry_Head.fieldbyname('InvBilltaxrate').asstring:=Extedt_InvBilltaxrate.Text;
  if chck_realPrice.Checked=True then
     AdoQry_Head.fieldbyname('InvBillValuation').asinteger:=0
  else
     AdoQry_Head.fieldbyname('InvBillValuation').asinteger:=1;
  //此程序不能做这一事件,因为用了CASE语句,所以不能增加
end;

procedure TFrm_Inv_PriceAudit_B.FormCreate(Sender: TObject);
begin
  inherited;
  Frm_Entry_Detail:=TFrm_Inv_PriceAudit_D.Create(Self);//设置弹出Detail
  SetFocus_Control:=edt_Date;//设置 新增时要聚焦的Control
end;


procedure TFrm_Inv_PriceAudit_B.SaveData;
var
  M,MArk,PriceAuditTimes:integer;
  Amount,oldAmount:real;
  currency,Billid,Billno,blueBillno,redBillno,Sourceno:string;
  InvBillValuation,Valuation,blue_InvBillValuation,blue_Valuation,tmp_memo:string;
  tmp_AdoQry:tAdoQuery;
begin
  if AdoQry_Body.state<>dsBrowse then
     AdoQry_Body.post;
  //取货币
  if BillTypeCode='0102' then
     currency:=getCode(lbl_Currency.Caption)
  else
     currency:='00';
  //核价的次数
  PriceAuditTimes:=AdoQry_Head.fieldbyname('PriceAuditTimes').asinteger+1;
  //单据是否改动标志,MArK=1未改动,下面从服务器取旧数据集
  MArk:=1;
  tmp_AdoQry:=tAdoQuery.Create(nil);
  tmp_AdoQry.Connection:=AdoQry_tmp.Connection;
  tmp_AdoQry.LockType:=ltBatchOptimistic;
  tmp_AdoQry.EnableBCD:=False;
  with tmp_AdoQry do
  begin
    Close;
    sql.clear;
    if BillTypeCode<>'0102' then
      sql.text:='select bl.InvBillid,'+
                 'bl.InvBilllineno,'+
                 'bl.pono,'+
                 'bl.polineno,'+
                 'bl.InvBillqty,'+
                 'bl.ItemCode,'+
                 'bl.BilllineremArk,'+
                 'bl.InvBillPrice,'+
                 'bl.InvBillAmount,'+
                 'bl.InvBillnotaxPrice,'+
                 'bl.InvBillnotaxAmount, '+
                 'bl.Valuation '+
          ' from InvInBillline bl'+
          ' where bl.InvBillid='+Bill_id+
          ' Order by bl.InvBillid,bl.InvBilllineno,bl.ItemCode '
    else
      sql.text:='select bl.InvBillid,'+
                 'bl.InvBilllineno,'+
                 'bl.pono,'+
                 'bl.polineno,'+
                 'bl.BilllineremArk,'+
                 'bl.InvBillqty,'+
                 'bl.ItemCode,'+
                 'bl.InvBillPricec as InvBillPrice,'+
                 'bl.InvBillAmountc as InvBillAmount,'+
                 'bl.InvBillnotaxPricec as InvBillnotaxPrice,'+
                 'bl.InvBillnotaxAmountc as InvBillnotaxAmount, '+
                 'bl.Valuation '+
          ' from InvInBillline bl'+
          ' where bl.InvBillid='+Bill_id+
          ' Order by bl.InvBillid,bl.InvBilllineno,bl.ItemCode ';
    open;
  end;
  //当前界面上的数据集与旧数据集比较,如果有改变,则MArK=0
  AdoQry_Body.First;

⌨️ 快捷键说明

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