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

📄 pm_enter_newautopo2.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 3 页
字号:
      Abort;
    end;
    If (AdoQry_Body.fieldbyname('PoLineDate').AsDateTime<Date()) Then
    begin
      DispInfo('第'+IntToStr(AdoQry_Body.RecNo)+'行数据约定交货日小于了系统工作日,请修改!',1);
      AdoQry_Body.EnableControls;
      Abort;
    end;
    SqlText:=' Select Case when PcLine.FormalPricePass=1 then PcLine.PcTaxPrice_Formal '
              +'             else PcLine.PcTaxPrice   '
              +'        end as PcTaxPrice, '
              +'        Case When PcLine.FormalPricePass=1 then PcLine.PcNoTaxPrice_Formal '
              +'             else PcLine.PcNoTaxPrice '
              +'        end as PcNoTaxPrice, '
              +'        Case When PcLine.FormalPricePass=1 then 0 '
              +'             else  1 end as PcReferencedPrice '
          +' From PcLine '
          +' Where (ItemCode='''+Trim(AdoQry_Body.fieldbyname('ItemCode').AsString)+''''
          +' )And (PcNo='''+Trim(Edt_PcNo.Text)+''')';
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.Text:=SqlText;
    AdoQry_Tmp.Open;
    If AdoQry_Tmp.Eof Then
    begin
      DispInfo('第'+IntToStr(I)+'行物料代码在相应的采购合同中找不到,不能存盘!',1);
      AdoQry_Body.EnableControls;
      Abort;
    end
    Else
    begin
      SqlText:=' Select Case when PcLine.FormalPricePass=1 then PcLine.PcTaxPrice_Formal '
              +'             else PcLine.PcTaxPrice   '
              +'        end as PcTaxPrice, '
              +'        Case When PcLine.FormalPricePass=1 then PcLine.PcNoTaxPrice_Formal '
              +'             else PcLine.PcNoTaxPrice '
              +'        end as PcNoTaxPrice, '
              +'        Case When PcLine.FormalPricePass=1 then 0 '
              +'             else  1 end as PcReferencedPrice '
              +' From PcLine '
              +' Where ('''+DateTimeToStr(AdoQry_Body.fieldbyname('PoLineDate').AsDateTime) +'''>= PcStArtDate '
              +' And '''+DateTimeToStr(AdoQry_Body.fieldbyname('PoLineDate').AsDateTime) +'''<= PcendDate) '
              +' And (('''+FloatToStr(AdoQry_Body.fieldbyname('PoQty').AsFloat)+'''>= PcStArtQty '
              +' And '''+FloatToStr(AdoQry_Body.fieldbyname('PoQty').AsFloat)+'''<PcendQty)'
              +' Or (PcStArtQty=0 And PcendQty=0)) '
              +' And (ItemCode='''+Trim(AdoQry_Body.fieldbyname('ItemCode').AsString)+''''
              +' )And (PcNo='''+Trim(Edt_PcNo.Text)+''')'
              +' And (PcLine.PcLineStatus=1)';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.Open;
      If Not AdoQry_Tmp.Eof Then
      begin
        With AdoQry_Body Do
        begin
          Edit;
          fieldbyname('POREFERENCEDPRICE').AsInteger:=AdoQry_Tmp.fieldbyname('PcREFERENCEDPRICE').AsInteger;
          fieldbyname('PoNoTaxPrice').AsFloat:=AdoQry_Tmp.fieldbyname('PcNoTaxPrice').AsFloat;
          fieldbyname('PONoTaxAmount').AsFloat:=AdoQry_Tmp.fieldbyname('PcNoTaxPrice').AsFloat*fieldbyname('PoQty').AsFloat;
          fieldbyname('PoTaxPrice').AsFloat:=AdoQry_Tmp.fieldbyname('PcTaxPrice').AsFloat;
          fieldbyname('PoTaxAmount').AsFloat:=AdoQry_Tmp.fieldbyname('PcTaxPrice').AsFloat*fieldbyname('PoQty').AsFloat;
          Post;
        end;
      end //在该段时间及数量内存在数据
      Else
      begin
        DispInfo('第'+IntTostr(I)+'行数据交货量或约定交货日与采购合同不匹配,请修改!',1);
        AdoQry_Body.EnableControls;
        Abort;
      end;
    end;
    AdoQry_Body.Next;
    I:=I+1;
  end; // end While
  Application.ProcessMessages;
  DbConnect.beginTrans;
  Try
    SqlText:='Select MrpParamValueN as aa From MrpParam Where MrpParamCode=''ReceiveOrder''';
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.Text :=SqlText;
    AdoQry_Tmp.Open;
    if AdoQry_Tmp.fieldbyname('aa').AsFloat<0.1 then
    begin
      AdoQry_Body.First ;
      while Not AdoQry_Body.Eof do
      begin
        if AdoQry_Body.fieldbyname('maxQty').AsFloat<AdoQry_Body.fieldbyname('poQty').AsFloat then
        begin
          DispInfo('第'+inttostr(AdoQry_Body.recno)+'行数据约定交货量大于系统建议余量,请修改!',1);
          If DbConnect.InTransaction Then
            DbConnect.RollBackTrans;
          AdoQry_Body.EnableControls;
          exit;
        end;
        AdoQry_Body.Next;
      end;
    end;
   AdoQry_Body.First;
    while not AdoQry_Body.Eof do
      begin
        updatessreMainqty(AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('ssid').asinteger,AdoQry_Body.fieldbyname('endssid').asinteger,AdoQry_Body.fieldbyname('poqty').asfloat,0);
        updatessreMainqty(AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('ssid').asinteger,AdoQry_Body.fieldbyname('endssid').asinteger,AdoQry_Body.fieldbyname('poqty').asfloat,1);
        updatec_Ss4reMainqty(AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('ssid').asinteger,AdoQry_Body.fieldbyname('endssid').asinteger,AdoQry_Body.fieldbyname('poqty').asfloat);
        AdoQry_Body.Next;
      end;
// with Frm_Pm_Enter_NewSsPoInfo4 do
//   begin
      AdoQry_Body.First;
      While Not AdoQry_Body.Eof Do
      begin
        If Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.Locate('SsId',AdoQry_Body.fieldbyname('Ssid').AsInteger,[loCaseInsensitive]) Then
        begin
         // BookmArk:=Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.BookmArk;
          Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.edit;
          if Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.fieldbyname('ReMainQty').AsFloat > AdoQry_Body.fieldbyname('poQty').AsFloat then
          begin
             Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.fieldbyname('ReMainQty').AsFloat:=Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.fieldbyname('ReMainQty').AsFloat-AdoQry_Body.fieldbyname('poQty').AsFloat;
             //Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.fieldbyname('ssReMainQty').AsFloat:=Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.fieldbyname('ssReMainQty').AsFloat-AdoQry_Body.fieldbyname('poQty').AsFloat;
          end
          else
           begin
             Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.fieldbyname('ReMainQty').AsFloat:=0;
             //Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.fieldbyname('ssReMainQty').AsFloat:=0;
           end;
          Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.fieldbyname('SScheck').AsInteger:=0;
          Frm_Pm_Enter_NewSsPoInfo4.AdoQry_Main.Post;
        end;
        AdoQry_Body.Next;
      end;

//   end;

 //修改#C_SS4
 //修改#C_SS1
 //修改#SS
 //修改SS
//-------
    If CurrentFormStatus='Add' Then
    begin
      PoNO:='P'+Trim(Copy(FormatDateTime('yyyy.mm.dd',Now),3,2))+Trim(Copy(FormatDateTime('yyyy.mm.dd',Now),6,2));
      Edt_PoNo.Text:=GetNo(DbConnect,PoNo,'Po');
      Application.ProcessMessages;
      SqlText:='Insert Po '
              +' (PoNo,VendorCode,PcNO,referenceno,POType,PODate,'
              +'  POTaxRate_Percent,CurrencyCode,EmployeeCode, PoSpecial,CreateEmpolyeeCode,PORemArk)'
              +'  Values('
              +''''+Trim(Edt_PoNo.Text)+''''+','
              +''''+Trim(Edt_VendorCode.Text)+''''+','
              +''''+Trim(Edt_PcNo.Text)+''''+','
              +quotedstr(Trim(edt_rno.text))+','
              +''''+IntToStr(Cmbx_PoType.ItemIndex)+''''+','
              +''''+Medt_PoDate.Text+''''+','
              +''''+Trim(Edt_PoTax.Text)+''''+','
              +''''+Trim(Edt_CurrencyCode.Text)+''''+','
              +''''+Trim(Edt_EmployeeCode.Text)+''''+','
              +''''+'0'+''''+','
              +QuotedStr(UserCode)+','
              +''''+Trim(Edt_PoReMArk.Text)+''''+')';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.ExecSQL;   // Insert Po Table
      If Not  SavePoHistory('Add') Then
        Abort;
      AdoQry_Body.First;
      While Not AdoQry_Body.Eof Do
      begin
        SqlText:='Insert PoLine '
                +' (PoNo,PoLineNo,ItemCode,POLineDate,PoStArtWorkDate,SsQty,POQty,POTaxPrice, '
                +' POTaxAmount,PONoTaxPrice,PONoTaxAmount,PONoFinishQty,POReferencedPrice,POLineStatus )'
                +' Values('
                +''''+Trim(Edt_PoNo.Text)+''','
                +''''+IntToStr(AdoQry_Body.fieldbyname('PoLineNo').AsInteger)+''','
                +''''+AdoQry_Body.fieldbyname('ItemCode').AsString+''','
                +''''+DatetimeToStr(AdoQry_Body.fieldbyname('PoLineDate').AsDateTime)+''','
                +''''+DatetimeToStr(AdoQry_Body.fieldbyname('PoStArtWorkDate').AsDateTime)+''',';
        If AdoQry_Body.fieldbyname('PoQty').AsFloat<=AdoQry_Body.fieldbyname('ssQty').AsFloat Then
          SqlText:=SqlText+''''+FloatToStr(AdoQry_Body.fieldbyname('PoQty').AsFloat)+''','
        Else
          SqlText:=SqlText+''''+FloatToStr(AdoQry_Body.fieldbyname('SsQty').AsFloat)+''',';
        SQlText:=SqlText+''''+FloatToStr(AdoQry_Body.fieldbyname('PoQty').AsFloat)+''','
                +''''+FloatToStr(AdoQry_Body.fieldbyname('POTaxPrice').AsFloat)+''','
                +''''+FloatToStr(AdoQry_Body.fieldbyname('POTaxAmount').AsFloat)+''','
                +''''+FloatToStr(AdoQry_Body.fieldbyname('PONoTaxPrice').AsFloat)+''','
                +''''+FloatToStr(AdoQry_Body.fieldbyname('PONoTaxAmount').AsFloat)+''','
                +''''+FloatToStr(AdoQry_Body.fieldbyname('PONoFinishQty').AsFloat)+''','
                +''''+IntToStr(AdoQry_Body.fieldbyname('POReferencedPrice').AsInteger)+''','
                +''''+IntToStr(AdoQry_Body.fieldbyname('POLineStatus').AsInteger)+''')';
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:=SqlText;
        AdoQry_Tmp.ExecSQL;
        OperationMOPO(AdoQry_Tmp,Trim(AdoQry_Body.fieldbyname('ItemCode').AsString),'po',1,
                   Trim(Edt_PoNo.Text),AdoQry_Body.fieldbyname('PoLineNo').AsInteger,AdoQry_Body.fieldbyname('POLINESTATUS').AsInteger,
                   0,AdoQry_Body.fieldbyname('PoQty').Asfloat,
                   AdoQry_Body.fieldbyname('PONoFinishQty').Asfloat,AdoQry_Body.fieldbyname('POStArtWorkDate').AsString,
                   AdoQry_Body.fieldbyname('POLineDATE').AsString,Cmbx_PoType.ItemIndex,Edt_VendorCode.text );
        If Not  SavePoLineHistory('Add') Then //保存历史记录
          Abort;
        If Cmbx_PoType.ItemIndex=1 Then //委外加工
{          IF Not AutoBuildOrder(DbConnect,Trim(Edt_PoNo.Text),Trim(AdoQry_Body.fieldbyname('ItemCode').AsString),IntToStr(AdoQry_Body.fieldbyname('PoLineNo').AsInteger),
                'Add','Po',AdoQry_Body.fieldbyname('PoQty').Asfloat) Then  //自动产生领料单
}
          IF Not NewAutoBuildopListOrder(DbConnect,Trim(Edt_PoNo.Text),IntToStr(AdoQry_Body.fieldbyname('PoLineNo').AsInteger),Trim(AdoQry_Body.fieldbyname('ItemCode').AsString),
             0,AdoQry_Body.fieldbyname('PoQty').Asfloat) Then  //自动产生领料单
           Abort;
        AdoQry_Body.Next;
      end;
    end;
//---------------
{    AdoQry_Temp.Connection := dbconnect;
    SqlText:='Select * from #C_Ss1';
    AdoQry_Temp.Close;
    AdoQry_Temp.SQL.Text := SqlText;
    AdoQry_Temp.Open;


//-------AdoQry_Body>>>>>-AdoQry_Temp---------
    AdoQry_Temp.First;
    While Not AdoQry_Temp.Eof Do
    begin
      If AdoQry_Temp.fieldbyname('PoQty').AsFloat<=AdoQry_Temp.fieldbyname('SsQty').AsFloat Then
      begin
        AdoQry_Temp.Edit;
        AdoQry_Temp.fieldbyname('SsQty').AsFloat:=AdoQry_Temp.fieldbyname('PoQty').AsFloat;
        AdoQry_Temp.Post;
      end;
      SqlText:='Update Ss '
              +'Set ReMainQty=ReMainQty-'''+(FloatToStr(AdoQry_Temp.fieldbyname('SsQty').AsFloat))+''''
              +'where Ssid='''+IntToStr(AdoQry_Temp.fieldbyname('LimItOut').AsInteger)+'''';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.ExecSQL;
      If AdoQry_Head.Locate('SsId',AdoQry_Temp.fieldbyname('LimItOut').AsInteger,[loCaseInsensitive]) Then
         begin
          BookmArk:=AdoQry_Head.BookmArk;
          AdoQry_Head.edit;
          AdoQry_Head.fieldbyname('ReMainQty').AsFloat:=AdoQry_Head.fieldbyname('ReMainQty').AsFloat-AdoQry_Body.fieldbyname('ssQty').AsFloat;
          AdoQry_Head.fieldbyname('SScheck').AsInteger:=0;
          AdoQry_Head.Post;

          SqlText:='Update #Ss '
              +'Set ssReMainQty=ssReMainQty-'''+(FloatToStr(AdoQry_Temp.fieldbyname('SsQty').AsFloat))+''''
              +'where Ssid='''+IntToStr(AdoQry_Temp.fieldbyname('LimItOut').AsInteger)+'''';
         AdoQry_Tmp.Close;
         AdoQry_Tmp.SQL.Text:=SqlText;
         AdoQry_Tmp.ExecSQL;

          AdoQry_Temp.Next;
         end;
    end;//更新表头数据}
    DbConnect.CommitTrans;
    AdoQry_Body.EnableControls;
    DispInfo('数据已保存!',3);
    if Frm_Pm_Enter_NewSsPoInfo<> nil then
    begin
//      if Frm_Pm_Enter_NewSsPoInfo.frentform=1 then
        Frm_Pm_Enter_NewSsPoInfo.Initselect
    end;
   { if Frm_Pm_Enter_NewSsPoInfo1<> nil then
      if Frm_Pm_Enter_NewSsPoInfo1.frentform=1 then
        Frm_Pm_Enter_NewSsPoInfo1.Initselect;  }
    if Frm_Pm_Enter_NewSsPoInfo2<> nil then
      if Frm_Pm_Enter_NewSsPoInfo2.frentform=1 then
        Frm_Pm_Enter_NewSsPoInfo2.Initselect ;

    if Frm_Pm_Enter_NewSsPoInfo1<> nil then
    begin
//      if Frm_Pm_Enter_NewSsPoInfo1.frentform=1 then
        Frm_Pm_Enter_NewSsPoInfo1.Initselect
    end;
    if Frm_Pm_Enter_NewSsPoInfo3<> nil then
      if Frm_Pm_Enter_NewSsPoInfo3.frentform=1 then
        Frm_Pm_Enter_NewSsPoInfo3.Initselect ;

    try
      AdoQry_Head.BookmArk:= BookmArk;
    except
    end;
  Except
    If DbConnect.InTransaction Then
      DbConnect.RollBackTrans;
    Edt_Pono.Text:='';
    AdoQry_Body.EnableControls;
    DispInfo('保存数据失败,请重试!',1);
    Abort;
  end;
  ActiveControl:=DBGridEh1;
  Act_InsertLine.Enabled:=False;
  Act_DeleteLine.Enabled:=False;
  Act_Modify.Enabled:=False;
  Act_Save.Enabled:=False;
  Edt_PcNo.Enabled:=False;
  Cmbx_PoType.Enabled:=False;
  Edt_EmployeeCode.Enabled:=False;
  DbGridEh1.Enabled:=False;
  Medt_PoDate.Enabled:=False;
  Act_Preview.Enabled:=True;
  Act_Print.Enabled:=True;
end;

procedure TFrm_Pm_Enter_NewAutoPo2.Edt_MoRemArkExit(Sender: TObject);
begin
  inherited;
  If (ActiveControl.Name='DBGridEh1') Or (ActiveControl.Name='ControlBar')  Then
    Exit;
  If (Not BlankCheck(TEdit(Sender).Text,'备注'))
    Or (Not checksymbol(TEdit(Sender).Text,'备注')) Then
  begin
    Twincontrol(Sender).SetFocus;
    Abort;
  end;

end;

procedure TFrm_Pm_Enter_NewAutoPo2.FormCreate(Sender: TObject);
begin
  inherited;
  ExtendCaption:=False;
  Frm_Entry_Detail:=TFrm_Pm_Enter_AutoPo_D.Create(Self);
  Medt_PoDate.Text:=FormatDateTime('yyyy.mm.dd',Date);
  With Cmbx_PoType Do
  begin
    Items.clear;
    Items.Add('0 普通采购');
    Items.Add('1 委外加工');
    Items.Add('2 一般贸易进口');
    Items.Add('3 加工贸易进口');
    Itemindex:=0;
  end;
  InitControls;

⌨️ 快捷键说明

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