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

📄 inv_opadjustbill_b.pas

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

Interface

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

Type
  TFrm_Inv_OpAdjustBill_B = Class(TFrm_Base_Entry_Body)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    edt_memo: TEdit;
    Edit2: TEdit;
    ledt_Vendor: TLinkEdit;
    edt_Billno: TEdit;
    medt_Date: TMaskEdit;
    Label7: TLabel;
    Label8: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure ledt_VendorExit(Sender: TObject);
    procedure Act_NewExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
  private
    { Private declarations }
    Billid,Billmemo,Billno,BillLoginDate,BillVendorCode,
    currencyCode,Vendortaxrate_Percent,BillHeadno,userName:string;
    Amount:real;
    showflag:boolean;
    function GetNo1(AdoConnection:TAdoConnection;PreStr:String):string;
  public
    { Public declarations }
    procedure savedata;Override;
    procedure InitControls; Override;
    procedure SaveHeadData; Override;

  end;

var
  Frm_Inv_OpAdjustBill_B: TFrm_Inv_OpAdjustBill_B;

implementation
uses Sys_Global,Inv_OpAdjustBill_D;
{$R *.DFM}

procedure TFrm_Inv_OpAdjustBill_B.savedata;
var
m,lineno:integer;
linenostr,updateMonth:string;
begin
  if AdoQry_Body.RecordCount<1 then
  begin
    DispInfo('新增的单据没有记录,不允许保存!',1);
    abort;
  end;
  lineno:=1;
  //主表存盘
  if AdoQry_Head.state<>dsBrowse then
    AdoQry_Head.post;

  if AdoQry_Body.state<>dsBrowse then
    AdoQry_Body.post;

  AdoQry_Body.DisableControls;
  AdoQry_Body.Connection.beginTrans;
  try
    updateMonth:=FormatDateTime('yyyy.mm',strtodate(medt_Date.Text));
    //取单据号
    Billno:=getno1(AdoQry_Body.Connection,'T'+copy(medt_Date.text,3,2)+copy(medt_Date.text,6,2));
    BillHeadno:=Billno;
    //记录本仓库数据发生改变
    //增加opAdjustBill
    AdoQry_tmp.Close;
    AdoQry_tmp.sql.clear;
    AdoQry_tmp.sql.Add('insert opAdjustBill'+
                       '(opBillno,'+
                       'opBilldate,'+
                       'opBillMonth,'+
                       'VendorCode,'+
                       'EmployeeCode,'+
                       'opBillcreatetime,'+
                       'opBillremArk) '+
               'Values('''+Billno+''','+
                      ''''+medt_Date.text+''','+
                      ''''+copy(medt_Date.text,1,7)+''','+
                      ''''+ledt_Vendor.Text+''','+
                      ''''+userCode+''','+
                      'getdate(),'+
                      ''''+edt_memo.text+''')');
    AdoQry_tmp.execsql;
    Billid:='';
    AdoQry_tmp.Close;
    AdoQry_tmp.sql.clear;
    AdoQry_tmp.sql.Add(' select @@IDENTITY as Billid ');
    AdoQry_tmp.open;
    Billid:=AdoQry_tmp.fieldbyname('Billid').asstring;
    Amount:=0;
    with AdoQry_Body do
    begin
      First;
      for M:=0 to recordCount-1 do
      begin
        //增加opAdjustBillline
        linenostr:=IntToStr(lineno);
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.clear;
        AdoQry_tmp.sql.Add('insert opAdjustBillline'+
                                     '(opBillid,'+
                                     'opBilllineno,'+
                                     'ItemCode,'+
                                     'opBillqty,'+
                                     'BilllineremArk,'+
                                     'opBillnotaxAmount )'+
                           'Values('+Billid+','+
                                   linenostr+','+
                                   ''''+fieldbyname('ItemCode').asstring+''','+
                                   fieldbyname('opBillqty').asstring+','+
                                   ''''+fieldbyname('BilllineremArk').asstring+''','+
                                   fieldbyname('opBillnotaxAmount').AsString+')' );
        AdoQry_tmp.ExecSQL;

        //修改OpMonthSum,将数量及金额增加到收入方
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.text:='select Count(*) as aa from OpMonthSum where VendorCode='+
                             QuotedStr(ledt_Vendor.Text)+' and InvMonth='+QuotedStr(updateMonth)+
                             ' and ItemCode='+QuotedStr(fieldbyname('ItemCode').asstring);
        AdoQry_tmp.open;
        if AdoQry_tmp.fieldbyname('aa').Value=0 then
        begin
           AdoQry_tmp.Close;
           AdoQry_tmp.sql.text:='insert OpMonthSum(InvMonth,VendorCode,ItemCode) Values('+
                             QuotedStr(updateMonth)+','+QuotedStr(ledt_Vendor.Text)+','+
                             QuotedStr(fieldbyname('ItemCode').asstring)+')';
           AdoQry_tmp.ExecSQL;
        end;
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.text:='update OpMonthSum set InvtzAmount=InvtzAmount+'+
                             fieldbyname('opBillnotaxAmount').AsString+','+
                             'InvblncAmount=InvblncAmount+'+
                             fieldbyname('opBillnotaxAmount').AsString+','+
                             'Invtzqty=Invtzqty+'+
                             fieldbyname('opBillqty').asstring+','+
                             'Invblncqty=Invblncqty+'+
                             fieldbyname('opBillqty').asstring+''+
                             ' where VendorCode='+
                             QuotedStr(ledt_Vendor.Text)+' and InvMonth='+QuotedStr(updateMonth)+
                             ' and ItemCode='+QuotedStr(fieldbyname('ItemCode').asstring);
        AdoQry_tmp.ExecSQL;
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.text:=' update OpMonthSum set InvblncPrice='+
                             ' case when Invblncqty<>0 then InvblncAmount/Invblncqty else 0 end '+
                             ' where VendorCode='+
                             QuotedStr(ledt_Vendor.Text)+' and InvMonth='+QuotedStr(updateMonth)+
                             ' and ItemCode='+QuotedStr(fieldbyname('ItemCode').asstring);
        AdoQry_tmp.ExecSQL;
///2001.12.30在MD调整
        //更新opCurrentInv---供应商材料结存
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.text:='select Count(*) as aa from opCurrentInv where VendorCode='+
                             QuotedStr(ledt_Vendor.Text)+
                             ' and ItemCode='+QuotedStr(fieldbyname('ItemCode').asstring);
        AdoQry_tmp.open;
        if AdoQry_tmp.fieldbyname('aa').Value=0 then
        begin
           AdoQry_tmp.Close;
           AdoQry_tmp.sql.text:='insert opCurrentInv(VendorCode,ItemCode) Values('+
                             QuotedStr(ledt_Vendor.Text)+','+
                             QuotedStr(fieldbyname('ItemCode').asstring)+')';
           AdoQry_tmp.ExecSQL;
        end;
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.text:='update opCurrentInv set opInv=opInv+'+
                             fieldbyname('opBillqty').asstring+
                             ' where VendorCode='+
                             QuotedStr(ledt_Vendor.Text)+
                             ' and ItemCode='+QuotedStr(fieldbyname('ItemCode').asstring);
        AdoQry_tmp.ExecSQL;
/////md 调整
        //更新opAveragePrice---供应商移动加权平均价
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.text:='select Count(*) as aa from opAveragePrice where VendorCode='+
                             QuotedStr(ledt_Vendor.Text)+
                             ' and ItemCode='+QuotedStr(fieldbyname('ItemCode').asstring);
        AdoQry_tmp.open;
        if AdoQry_tmp.fieldbyname('aa').Value=0 then
        begin
           AdoQry_tmp.Close;
           AdoQry_tmp.sql.text:='insert opAveragePrice(VendorCode,ItemCode) Values('+
                             QuotedStr(ledt_Vendor.Text)+','+
                             QuotedStr(fieldbyname('ItemCode').asstring)+')';
           AdoQry_tmp.ExecSQL;
        end;
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.text:='update opAveragePrice set opApAmount=opApAmount+'+
                             fieldbyname('opBillnotaxAmount').AsString+','+
                             'opApqty=opApqty+'+
                             fieldbyname('opBillqty').asstring+
                             ' where VendorCode='+
                             QuotedStr(ledt_Vendor.Text)+
                             ' and ItemCode='+QuotedStr(fieldbyname('ItemCode').asstring);
        AdoQry_tmp.ExecSQL;
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.text:=' update opAveragePrice set opAveragePrice='+
                             ' case when opApqty<>0 then opApAmount/opApqty else 0 end '+

⌨️ 快捷键说明

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