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

📄 inv_purchinaudit_b.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Inv_PurchInAudit_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, jpeg;

Type
  TFrm_Inv_PurchInAudit_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;
    lbl_Date: TLabel;
    Label6: TLabel;
    Label2: TLabel;
    lbl_Pono: TLabel;
    Label9: TLabel;
    lbl_Vendor: TLabel;
    Label12: TLabel;
    lbl_Currency: TLabel;
    chkbx_PoreferencedPrice: TCheckBox;
    Extedt_memo: TExtEdit;
    Extedt_InvBilltaxrate: TExtEdit;
    Label7: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Act_QuitExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Extedt_InvBilltaxrateExit(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Act_PreviewExecute(Sender:Tobject);
    procedure Act_PrintExecute(Sender:Tobject);
    procedure Act_SaveExecute(Sender: TObject);
  private
    BillTypeCode:string;
    fExchRate:string;
    oldInvBilltaxrate: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_PurchInAudit_B: TFrm_Inv_PurchInAudit_B;

implementation

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




procedure TFrm_Inv_PurchInAudit_B.InitControls;
var
  body_Sqltext:string;
  enabledact_Modify:boolean;
begin//初始化Form上的控件
  BillTypeCode:=Param1;
  inherited;
  //单据类型

  Bill_ID:=AdoQry_Head.fieldbyname('InvBillid').AsString ;

  if AdoQry_Head.fieldbyname('InvBillwhchck').Asinteger<>1 then
  begin
    //可以修改
    body_Sqltext:='select bl.InvBillid,'+
                   'bl.InvBilllineno,'+
                   'bl.pono,'+
                   'bl.polineno,'+
                   'bl.InvBillqty,'+
                   'bl.ItemCode,'+
                   'i.ItemName,'+
                   'u.UomName,'+
                   'p.currencyCode,'+
                   'c.currencyName,'+
                   'pl.poreferencedPrice,'+
                   'pl.potaxPrice as InvBillPrice,'+
                   'bl.InvBillAmount,'+
                   'pl.ponotaxPrice as InvBillnotaxPrice,'+
                   'bl.InvBillnotaxAmount'+
            ' from InvInBillline bl'+
            '  left join poline pl on bl.pono=pl.pono '+
            '                     and bl.polineno=pl.polineno '+
            '  left join po p on pl.pono=p.pono '+
            '  left join currency c on p.currencyCode=c.currencyCode '+
            '  left join Item i on bl.ItemCode=i.ItemCode '+
            '  left join Uom u on i.UomCode=u.UomCode '+
            ' where bl.InvBillid='+Bill_id
  end
  else
  begin
    //只能查看
    //如果不是进口‘0102’ 取不是进口的单价,金额,否则取进口单价,金额
    if BillTypeCode<>'0102' then
       body_Sqltext:='select bl.InvBillid,'+
                   'bl.InvBilllineno,'+
                   'bl.pono,'+
                   'bl.polineno,'+
                   'bl.InvBillqty,'+
                   'bl.ItemCode,'+
                   'i.ItemName,'+
                   'u.UomName,'+
                   'bl.InvBillPrice,'+
                   'bl.InvBillAmount,'+
                   'bl.InvBillnotaxPrice,'+
                   'bl.InvBillnotaxAmount '+
            ' 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
    else
    begin
      act_Save.Enabled :=False;
      act_Modify.Enabled :=False;
      body_Sqltext:='select bl.InvBillid,'+
                   'bl.InvBilllineno,'+
                   'bl.pono,'+
                   'bl.polineno,'+
                   'bl.InvBillqty,'+
                   'bl.ItemCode,'+
                   'i.ItemName,'+
                   'u.UomName,'+
                   'bl.InvBillPricec as InvBillPrice,'+
                   'bl.InvBillAmountc as InvBillAmount,'+
                   'bl.InvBillnotaxPricec as InvBillnotaxPrice,'+
                   'bl.InvBillnotaxAmountc as InvBillnotaxAmount'+
            ' 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
    end;
  end;
  with AdoQry_Body do
  begin
    Close;
    sql.clear;
    sql.Add(body_Sqltext);
    open;
    //显示暂估价
    if AdoQry_Head.fieldbyname('InvBillwhchck').Asinteger<>1 then
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if fieldbyname('poreferencedPrice').asinteger=1 then
        begin
           chkbx_PoreferencedPrice.checked:=True;
           break;
        end;
        next;
      end;
      First;
      while not eof do
      begin
        edit;
        fieldbyname('InvBillAmount').asfloat:=fieldbyname('InvBillPrice').asfloat*fieldbyname('InvBillqty').asfloat;
        fieldbyname('InvBillnotaxAmount').asfloat:=fieldbyname('InvBillnotaxPrice').asfloat*fieldbyname('InvBillqty').asfloat;
        next;
      end;
      First;
      enablecontrols;
    end
    else
    begin
      if AdoQry_Head.fieldbyname('InvBillValuation').asinteger=1 then
        chkbx_PoreferencedPrice.checked:=True
      else
        chkbx_PoreferencedPrice.checked:=False;
    end;
  end;

  //显示表头各控键初始值
  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_Date.Caption:=datetimetostr(fieldbyname('InvBilldate').asdatetime);
    lbl_Pono.Caption:=fieldbyname('pono').asstring;
    Extedt_memo.text:=fieldbyname('InvBillremArk').asstring;
    Extedt_Billno.text:=fieldbyname('InvBillno').asstring;

    //分别处理修改及查询显示
    //显示币种,审核的是从PO表中取得CURRENCYCode, 税率potaxrate_Percent, 查询是从InvInBill表中取得CURRENCYCode,税率InvBillTAXRATE
    if fieldbyname('InvBillwhchck').Asinteger<>1 then
    begin

      with AdoQry_tmp do
      begin
        Close;
        sql.clear;
        sql.Add('select p.currencyCode,c.currencyName '+
                ' from po p,currency c '+
                '  where p.pono='''+AdoQry_Head.fieldbyname('pono').asstring+''''+
                '    and p.currencyCode=c.currencyCode ');
        open;
        lbl_Currency.Caption:=fieldbyname('currencyCode').asstring+' '+fieldbyname('currencyName').asstring;
      end;
      //从po中取得税率,币种
      with AdoQry_tmp do
      begin
        Close;
        sql.clear;
        sql.Add('select potaxrate_Percent from po where pono='''+lbl_Pono.Caption+'''');
        open;
        Extedt_InvBilltaxrate.text:=fieldbyname('potaxrate_Percent').asstring;
        oldInvBilltaxrate:=Extedt_InvBilltaxrate.text;
      end
    end
    else
    begin
      //查询
      with AdoQry_tmp do
      begin
        Close;
        sql.clear;
        sql.Add('select i.currencyCode,c.currencyName '+
                ' from InvInBill i,currency c '+
                '  where i.InvBillid='+AdoQry_Head.fieldbyname('InvBillid').asstring+
                '    and i.currencyCode=c.currencyCode ');
        open;
        lbl_Currency.Caption:=fieldbyname('currencyCode').asstring+' '+fieldbyname('currencyName').asstring;
      end;
      //从InvInvbil中取得税率,币种
      with AdoQry_tmp do
      begin
        Close;
        sql.clear;
        sql.Add('select InvBilltaxrate from InvInBill where InvBillid='+AdoQry_Head.fieldbyname('InvBillid').asstring);
        open;
        Extedt_InvBilltaxrate.text:=fieldbyname('InvBilltaxrate').asstring;
        oldInvBilltaxrate:=Extedt_InvBilltaxrate.text;
      end
    end;
  end;

end;


procedure TFrm_Inv_PurchInAudit_B.SetStatus(CurrentStatus:String;var AnswerStatus,
  EnableControls:String);
var
  currencyCode,currencyName:string;
begin//指明当前状态,定义Enable=True的控件
  inherited;
  fExchRate:='1';
  if BillTypeCode='0102' then
  begin
    if AdoQry_Head.fieldbyname('InvBillwhchck').Asinteger<>1 then
    begin
      AdoQry_tmp.Close;
      AdoQry_tmp.sql.clear;
      AdoQry_tmp.sql.Add('select po.currencyCode,currency.currencyName '+
              ' from po,currency '+
              ' where po.pono='''+AdoQry_Head.fieldbyname('pono').Asstring+''''+
              '   and po.currencyCode=currency.currencyCode');
      AdoQry_tmp.open;
      currencyCode:=AdoQry_tmp.fieldbyname('currencyCode').asstring;
      currencyName:=AdoQry_tmp.fieldbyname('currencyName').asstring;
      AdoQry_tmp.Close;
      AdoQry_tmp.sql.clear;
      AdoQry_tmp.sql.Add('select ExchRate '+
          ' from ExchRate '+
          'where exchMonth='''+copy(AdoQry_Head.fieldbyname('InvBilldate').Asstring,1,7)+''' and '+
          '      currencyCode='''+currencyCode+'''');
      AdoQry_tmp.open;
      if AdoQry_tmp.eof then
      begin
        AnswerStatus:='ReadOnly';
        EnableControls:='';
        DispInfo('币种:'+currencyCode+' '+currencyName+' '+copy(AdoQry_Head.fieldbyname('InvBilldate').Asstring,1,7)+'月的汇率没有定义,不能进行核价!',1);
      end
      else
      begin
        AnswerStatus:='Edit';
        EnableControls:='Extedt_InvBilltaxrate,Extedt_memo,';
        fExchRate:=AdoQry_tmp.fieldbyname('ExchRate').asstring;
      end;
    end
    else
    begin
      AnswerStatus:='ReadOnly';
      EnableControls:='';
    end;
  end
  else
  begin
    if AdoQry_Head.fieldbyname('InvBillwhchck').Asinteger<>1 then
    begin
      AnswerStatus:='Edit';
      EnableControls:='Extedt_InvBilltaxrate,Extedt_memo,';
    end
    else
    begin
      AnswerStatus:='ReadOnly';
      EnableControls:='';
    end;
  end;



 // if (AdoQry_Head.fieldbyname('InvBillwhchck').asinteger=1) or (act_Modify.enabled=False) then
 { if status='Edit' then
  begin
    if AdoQry_Head.fieldbyname('InvBillwhchck').Asinteger=1 then
    begin
      AnswerStatus:='ReadOnly';
      EnableControls:='';
    end
    else
    begin
      AnswerStatus:='AllEdit';
      //当单据体有数据时,单据头Enable=True 的控件
      EnableControls:='Extedt_InvBilltaxrate,Extedt_memo,';
    end;
  end
  else
  begin
    AnswerStatus:='AllEdit';
    //当单据体有数据时,单据头Enable=True 的控件
    EnableControls:='Extedt_InvBilltaxrate,Extedt_memo,';
  end;}
end;

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

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

end;

procedure TFrm_Inv_PurchInAudit_B.SaveData;
var
  M:integer;
  Amount:real;
  Billid,Billno,currency,tmp_Str:string;
begin
  inherited;
 if AdoQry_Body.state<>dsBrowse then
    AdoQry_Body.post;

 SaveHeadData;

  AdoQry_Body.Connection.beginTrans;
  try

    //真正开始存盘

       //记录本仓库数据发生改变
    ChangeInvStatus(AdoQry_tmp,getCode(lbl_WhCode.Caption),copy(lbl_Date.Caption,1,7));


     //更改InvInBill
    if chkbx_PoreferencedPrice.State=cbchecked then
      tmp_Str:='InvBillValuation=1 '
    else
      tmp_Str:='InvBillValuation=0 ';
    AdoQry_tmp.Close;
    AdoQry_tmp.sql.clear;
    AdoQry_tmp.sql.Add('update InvInBill'+
                       '  set InvBilltaxrate='+Extedt_InvBilltaxrate.text+','+
                            ' currencyCode='''+getCode(lbl_Currency.Caption)+''','+
                            ' InvBillStkchck=1, '+
                            ' Stk_EmployeeCode='''+userCode+''','+
                            tmp_Str+
                       ' where InvBillid='+AdoQry_Head.fieldbyname('InvBillid').asstring);
    AdoQry_tmp.execsql;

    with AdoQry_Body do
    begin
      Amount:=0;
      First;
      for M:=0 to recordCount-1 do
      begin
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.clear;
        //更改加权平均价  不存在 仓库代码=当前仓库代码 and  物料代码=当前物料代码的记录,则Insert一行这样的新记录
        AdoQry_tmp.sql.Add(' if not exists (select Apqty from AveragePrice '+
                                           ' where whCode='''+getCode(lbl_WhCode.Caption)+''' and '+
                                           ' ItemCode='''+fieldbyname('ItemCode').asstring+''')'+
                           ' insert AveragePrice(whCode,ItemCode) '+
                                        ' Values('''+getCode(lbl_WhCode.Caption)+''','+
                                                ''''+fieldbyname('ItemCode').asstring+''')'+
                           ' update AveragePrice '+
                           '  set Apqty=Apqty+'+fieldbyname('InvBillqty').asstring+','+
                               '  ApAmount=ApAmount+'+fieldbyname('InvBillnotaxAmount').asstring+'*'+fExchRate+

⌨️ 快捷键说明

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