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

📄 inv_otheropout_b.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  Price : double;
  Flagfloat :double;
  ItemInvField,CurrentInvField:string;
  NeedChangePrice:Boolean;
  sql_txt:string;
begin
  inherited;
  FlagFloat:=0;
  with AdoQry_Tmp do
  begin
    Close;
    sql.text:='select PriceType '+
              '  from Warehouse '+
              ' where whCode='''+getCode(Cmbx_WhCodeName.text)+''' ';
    Prepared;
    open;
    if (not eof) and (fieldbyname('PriceType').asinteger=1) then
    IsPlanPrice:=True
    else IsPlanPrice:=False;
  end;
  if (AdoQry_Body.RecordCount<1) and (Status='Add') then
  begin
    DispInfo('新增的单据没有记录,不允许保存!',1);
    abort;
  end;
  //全面类型、日期检查
  Edt_OutCodeExit(Edt_OutCode);
  if AdoQry_Head.state<>dsBrowse then
    AdoQry_Head.post;
  if AdoQry_Body.state<>dsBrowse then
    AdoQry_Body.post;
  //AdoQry_Body.DisableControls ;
  AdoQry_Tmp.Connection.beginTrans;
  ItemInvField:=GetInvField(AdoQry_Tmp,GetCode(Cmbx_WhCodeName.text),GetCode(Cmbx_Position.Text),'Item');
  CurrentInvField:=GetInvField(AdoQry_Tmp,GetCode(Cmbx_WhCodeName.text),GetCode(Cmbx_Position.Text),'CurrentInv');
  NeedChangePrice:=NeedChangeAveragePrice(AdoQry_Tmp,copy(Medt_Date.text,1,7));
  try
    //检查日期、库存
    medt_Date.onexit(medt_Date);
    AdoQry_Body.First;
    for M:=0 to AdoQry_Body.recordCount-1 do
    begin
      if not InvQtyCheck
          (NeedChangePrice,
           AdoQry_Body,
           AdoQry_tmp,
           getCode(Cmbx_WhCodeName.text),
           getCode(Cmbx_Position.Text),
           AdoQry_Body.fieldbyname('ItemCode').asstring,
           'InvBillQty',
           AdoQry_Body.fieldbyname('InvBillQty').asfloat,
           False) then
        abort;
      if AdoQry_Body.fieldbyname('BatchNo').asstring<>'' then
        if not BatchInvCheck(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').asstring,
                             'c',getCode(Cmbx_WhCodeName.text),
                                 getCode(Cmbx_Position.text),
                                 AdoQry_Body.fieldbyname('InvBillQty').asFloat) then Abort;
      AdoQry_Body.next;
    end;
    //取单据号
    If Status='Add' then
    Billno:=getno(AdoQry_Body.Connection,getCode(Cmbx_WhCodeName.Text)+'C'+copy(medt_Date.text,3,2)+copy(medt_Date.text,6,2),'InvBill')
    Else
    Billno:=Trim(Edt_BillNo.Text);
       //记录本仓库数据发生改变
    ChangeInvStatus(AdoQry_tmp,getCode(Cmbx_WhCodeName.text),copy(Medt_Date.text,1,7));
     //增加InvOutBill
    OutfieldName:='VendorCode,';
    OutFieldValue:=''''+Edt_OutCode.Text+''',';
    If Status='Add' then
    begin
    AdoQry_tmp.Close;
    AdoQry_tmp.sql.clear;
    AdoQry_tmp.sql.Add('insert into InvOutBill'+
                               '(InvBillno,'+
                               'whCode,'+
                               'InvBilldate,'+
                               'InvBillMonth,'+
                               'BillTypeCode,'+
                               'BillType2Code,'+
                               'EmployeeCode,'+
                               'Stk_EmployeeCode,'+
                               OutFieldName+    //此处必须做个处理,因为写入的字段不确定!
                               'WhPositionCode,'+
                               'InvBillWHChck,'+
                               'opBill,'+
//                               'PriceAdjustBill,'+
                               'InvBillremArk)'+
               'Values('''+Billno+''','+
                      ''''+getCode(Cmbx_WhCodeName.text)+''','+
                      ''''+medt_Date.text+''','+
                      ''''+copy(medt_Date.text,1,7)+''','+
                      ''''+BillTypeCode+''','+
                      ''''+'115'+''','+
                      ''''+userCode+''','+
                      ''''+userCode+''','+
                      OutFieldValue+
                      //-------
                      ''''+getCode(Cmbx_Position.text)+''','+
                      ' ''1'','+
                      ' ''1'','+
//                      ''''+inttostr(ord(ChckBx_PriceAdjust.checked))+''','+
                      ''''+Edt_memo.text+''')');
    AdoQry_tmp.execsql;
    //取InvBillID
    AdoQry_tmp.Close;
    AdoQry_tmp.sql.clear;
    AdoQry_tmp.sql.Add(' select @@IDENTITY as Billid ');
    AdoQry_tmp.open;
    Billid:=AdoQry_tmp.fieldbyname('Billid').asstring;
    end Else
    begin
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.clear;
      AdoQry_Tmp.Sql.Add('select InvBillId from InvOutBill where InvBillNo='''+BillNo+'''');
      AdoQry_tmp.Open;
      BillId:=AdoQry_Tmp.fieldbyname('InvBillId').ASString;
      If Length(OutFieldName)>2 then
      begin
        OutFieldName:=Copy(OutFieldName,1,Length(OutFieldName)-1)+'=';
        OutFieldValue:=OutFieldValue;
      end;
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.clear;
      AdoQry_Tmp.SQL.Add('update InvOutBill '+
                           'set '+
                               'InvBillDate='''+Medt_Date.text+''','+
                               'InvBillMonth='''+Copy(Medt_Date.text,1,7)+''','+
                               'Stk_EmployeeCode='''+UserCode+''','+
                               'InvBillWhchck=1,'+
                               'BillTypeCode='''+BillTypeCode+''','+
                               'BillType2Code='''+getCode(Cmbx_BillType2CodeName.text)+''','+
                                OutFieldName+OutFieldValue+
                               'WhPositionCode='''+getCode(Cmbx_Position.text)+''','+
                               'DeptCode=null, '+
//                               'VendorCode='''+edt_OutCode.text+''', '+
                               'CUSTOMERCode=null, '+
                               'InvOutBill.OpBill=1,'+
//                               'PriceAdjustBill='+inttostr(ord(ChckBx_PriceAdjust.checked))+','+
                               'InvBillRemArk='''+Trim(Edt_Memo.text)+''' '+
                         'where InvBillId='+Billid);
     AdoQry_Tmp.ExecSQL;

     AdoQry_Tmp.Close;
     AdoQry_Tmp.SQL.clear;
     AdoQry_Tmp.Sql.Add('Delete from InvOutBillLine '+
                        'where InvBillId='''+BillId+'''');
     AdoQry_Tmp.ExecSQL;
    end;
    with AdoQry_Body do
    begin
      First;
      for M:=0 to recordCount-1 do
      begin
        //增加InvBillLINE
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.clear;
        AdoQry_tmp.sql.Add('insert into InvOutBillline'+
                                     '(InvBillid,'+
                                     'BatchNo,'+
                                     'InvBilllineno,'+
                                     'InvBillNoTaxPrice,'+
                                     'InvBillNoTaxAmount,'+
                                     'ItemCode,'+
                                     'InvBillSfcqty,'+//by johnson
                                     'InvBillqty,BillLineRemArk)'+
                           'Values('+Billid+','+
                                   ''''+fieldbyname('BatchNo').asstring+''','+
                                   inttostr(M+1)+','+
                                   fieldbyname('InvBillnotaxPrice').asstring+','+
                                   fieldbyname('InvBillnotaxAmount').asstring+','+
                                   ''''+fieldbyname('ItemCode').asstring+''','+
                                   ''''+fieldbyname('InvBillqty').asstring+''','+//by johnson
                                   fieldbyname('InvBillqty').asstring+
                                   ' ,'''+fieldbyname('BillLineRemArk').asstring+''')');
        AdoQry_tmp.ExecSQL;
        if True then//NeedChangePrice then
        begin
          If (not IsPlanPrice) then
          begin
          AdoQry_tmp.Close;
          AdoQry_tmp.sql.clear;
          AdoQry_Tmp.Sql.Add('Insert Into AveragePrice'+
                             '       (whCode,ItemCode)'+
                             '     select '''+getCode(Cmbx_WhCodeName.Text)+''', '+
                             '            '''+fieldbyname('ItemCode').AsString+''' '+
                             '     where  '''+getCode(Cmbx_WhCodeName.Text)+'''+'+
                             '            '''+fieldbyname('ItemCode').AsString+''' not in '+
                             '            (Select rTrim(whCode)+rTrim(ItemCode) '+
                             '               from AveragePrice) ');
          AdoQry_Tmp.ExecSQL;

          AdoQry_tmp.Close;
          AdoQry_tmp.sql.clear;
          AdoQry_Tmp.Sql.Add('UpDate AveragePrice'+
                              ' Set ApQty=ApQty-('+AdoQry_Body.fieldbyname('InvBillQty').AsString+'),'+
                                  ' ApAmount=ApAmount-('+fieldbyname('InvBillnotaxAmount').asstring+') '+
                             ' where whCode='''+getCode(Cmbx_WhCodeName.Text)+''' and '+
                             '       ItemCode='''+fieldbyname('ItemCode').AsString+'''');
          AdoQry_Tmp.ExecSQL;

          AdoQry_tmp.Close;
          AdoQry_tmp.sql.clear;
          AdoQry_Tmp.Sql.Add('UpDate AveragePrice'+
                                ' set AveragePrice='+
                             'Case when ApQty=0 then '+
                             ' AveragePrice else ApAmount/Apqty end '+
                             ' where whCode='''+getCode(Cmbx_WhCodeName.Text)+''' and '+
                             '       ItemCode='''+fieldbyname('ItemCode').AsString+'''');
          AdoQry_Tmp.ExecSQL;
          end;
        end;

        if UpdateInv(AdoQry_Tmp,
                  getCode(Cmbx_WhCodeName.text),
                  getCode(Cmbx_Position.text),
                  AdoQry_Body.fieldbyname('ItemCode').asstring,
                  '(-('+AdoQry_Body.fieldbyname('InvBillQty').asstring+'))',
                  NeedChangePrice,True)<>'' then
         abort;

        if AdoQry_Body.fieldbyname('BatchNO').asstring<>'' then
        ChangeBatchInv(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNO').asstring,
                       'c',formatdatetime('YYYY.MM.DD',date),
                       getCode(Cmbx_WhCodeName.text),
                       getCode(Cmbx_Position.text),
                       AdoQry_Body.fieldbyname('InvBillQty').asFloat);
        //如果要更新改变供应商委外材料库存,则...
        if True then//NeedChangePrice then
        begin
        //更新移动加权平均价
          AdoQry_tmp.Close;
          AdoQry_tmp.SQL.text:='select * from opAveragePrice '+
                               ' where VendorCode='''+getCode(Edt_OutCode.Text)+''' and '+
                               '       ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''';
          AdoQry_tmp.Open;

          If AdoQry_tmp.IsEmpty then
          begin
            AdoQry_tmp.Close;
            AdoQry_tmp.SQL.text:='insert into opAveragePrice(VendorCode,ItemCode,opApAmount,opApqty,opAveragePrice) '+
                                 'select '''+getCode(edt_OutCode.text)+''','+
                                 '       '''+AdoQry_Body.fieldbyname('ItemCode').AsString+''','+
                                 '       0,0,0';
            AdoQry_tmp.execsql;
          end;

          AdoQry_tmp.Close;
          AdoQry_tmp.sql.clear;
          sql_txt:='UpDate OpAveragePrice'+
                            ' Set OpApQty=OpApQty+('+
                                       AdoQry_Body.fieldbyname('InvBillQty').AsString+'),'+
                                   'OpApAmount=round(OpApAmount+'+fieldbyname('InvBillNoTaxAmount').AsString+',2),'+
                                   'OpAveragePrice=case when (opApqty+('+AdoQry_Body.fieldbyname('InvBillQty').AsString+'))=0 then 0 else '+
                                   '                round(opApAmount+'+fieldbyname('InvBillNoTaxAmount').AsString+',2)/'+
                                   '               (OpApQty+('+AdoQry_Body.fieldbyname('InvBillQty').AsString+')) end '+
                              ' where VendorCode='''+getCode(Edt_OutCode.Text)+''' and '+
                              '       ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''';
          AdoQry_Tmp.Sql.Add(sql_txt);
          AdoQry_Tmp.ExecSQL;
        end;
        //插入opCurrentInv中没有的记录
        AdoQry_Tmp.Close;
        AdoQry_Tmp.Sql.clear;
        AdoQry_Tmp.SQL.Add('Select Count(*) as RecCount from OPCurrentInv '+
                           '  Where VendorCode='''+GetCode(Edt_OutCode.text)+''''+
                           '    and ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''');
        AdoQry_Tmp.Open;

        If AdoQry_Tmp.fieldbyname('RecCount').AsInteger<=0 then
        begin
          AdoQry_tmp.Close;
          AdoQry_Tmp.Sql.clear;
          AdoQry_Tmp.SQL.Add('Insert OPCurrentInv '+
                             '        (VendorCode,'+
                             '         ItemCode,'+
                             '         OpInv)'+
                             'Values('''+GetCode(Edt_OutCode.text)+''','+
                             ''''+AdoQry_Body.fieldbyname('ItemCode').AsString+''','+
                             '0)');
          AdoQry_Tmp.ExecSQL;
        end;
        //更新委外库存
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.clear;
        AdoQry_tmp.SQL.Add('Update OPCurrentInv Set'+
                           '  OpInv=OpInv+'+AdoQry_Body.fieldbyname('InvBillQty').AsString+
                           '  Where VendorCode='''+GetCode(Edt_OutCode.text)+''''+
                           '    and ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''');
        AdoQry_Tmp.ExecSQL;

        next;
      end;
    end;
    AdoQry_Tmp.Connection.CommitTrans;
    AdoQry_Body.EnableControls ;
    edt_Billno.text:=Billno;
    Act_Save.Enabled:=False;
    Cmbx_WhCodeName.Enabled:=False;
    Cmbx_Position.Enabled:=False;
    Edt_OutCode.Enabled:=False;
//    chckbx_PriceAdjust.Enabled:=False;
    Cmbx_BillType2CodeName.Enabled:=False;
    Medt_Date.enabled:=False;
    Edt_BillNo.Enabled:=False;
    act_insertline.enabled:=False;
    act_Deleteline.enabled:=False;

⌨️ 快捷键说明

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