inv_noorderopin_b.pas

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

PAS
1,160
字号
        +' '+Billid+''
        +','''+AdoQry_RealOpQty.fieldbyname('InvBillLineNo').AsString+''''
        +','''+AdoQry_RealOpQty.fieldbyname('Ite_ItemCode').AsString+''''
        +','''+AdoQry_RealOpQty.fieldbyname('ItemCode').AsString+''''
        +','+AdoQry_RealOpQty.fieldbyname('RealOpQty').AsString+''
        +','+AdoQry_RealOpQty.fieldbyname('RealOpQtyNew').AsString+''
        +','+AdoQry_RealOpQty.fieldbyname('RealOPScrAp_Percent').AsString+''
        +','+AdoQry_RealOpQty.fieldbyname('RealOPScrAp_PercentNew').AsString+')';
{        +' Else'
        +' Update RealOpQty Set'
        +' RealOpQtyNew='+AdoQry_RealOpQty.fieldbyname('RealOpQtyNew').AsString+''
        +',RealOPScrAp_PercentNew='+AdoQry_RealOpQty.fieldbyname('RealOPScrAp_PercentNew').AsString
        +' Where InvBillId='+AdoQry_RealOpQty.fieldbyname('InvBillId').AsString
        +' And InvBillLineNo='''+AdoQry_RealOpQty.fieldbyname('InvBillLineNo').AsString+''''
        +' And Ite_ItemCode='''+AdoQry_RealOpQty.fieldbyname('Ite_ItemCode').AsString+''''
        +' And ItemCode='''+AdoQry_RealOpQty.fieldbyname('ItemCode').AsString+'''';
}
      AdoQry_Tmp.ExecSQL;
      AdoQry_RealOpQty.Next;
    end;


    AdoQry_Body.First;
    while not AdoQry_Body.Eof do
    begin
      //根据新定额,新损耗重新更新OPBill
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:='Insert OPBill (InvBillId,InvBillLineNo,ItemCode'
        +',OPBillQty)'
        +' Select InvBillId'
        +',InvBillLineNo'
        +',ItemCode'
        +',Sum(IsNull(RealOpQtyNew*(1+RealOPScrAp_PercentNew/100)'
        +'*('+AdoQry_Body.fieldbyname('InvBillQty').AsString+'),0))'
        +' From RealOpQty'
        +' Where InvBillId='+Billid
        +' And InvBillLineNo='''+AdoQry_Body.fieldbyname('InvBillLineNo').AsString+''''
        +' Group By InvBillId,InvBillLineNo,ItemCode';
      AdoQry_Tmp.ExecSQL;

      //减少供应商端的材料库存OPCurrentInv
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:='Insert OPCurrentInv(VendorCode,ItemCode)'
        +' Select Distinct '''+Extedt_OutCode.text+''',ItemCode'
        +' From OPBill'
        +' Where InvBillId='+BillId+''
        +' And ItemCode Not In'
        +'(Select ItemCode'
        +' From OPCurrentInv'
        +' Where VendorCode='''+Extedt_OutCode.text+''')';
      AdoQry_Tmp.ExecSQL;
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:='Update OPCurrentInv'
        +' Set OPInv=OPInv-OPBill.OPBillQty'
        +' From (Select ItemCode,Sum(OPBillQty) As OPBillQty From OPBill'
        +' Where InvBillId='+BillId
        +' Group By ItemCode) OPBill'
        +' Where OPCurrentInv.VendorCode='''+Extedt_OutCode.text+''''
        +' And OPCurrentInv.ItemCode=OPBill.ItemCode';
      AdoQry_Tmp.ExecSQL;
      //更新OpBill数据表的单价,金额
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:='Update OPBill Set'
        +' OPBillNoTaxPrice=case when opAp.OPAveragePrice=0 then 0 else opAp.OPAveragePrice end '
        +',OPBillNoTaxAmount=Round((case when opAp.OPAveragePrice=0 then 0 else opAp.OPAveragePrice end)*OPBill.OPBillQty,2)'
        +' From OPAveragePrice opAp '
        +' Where opAp.VendorCode='''+Extedt_OutCode.text+''''
        +' And opAp.ItemCode=OPBill.ItemCode'
        +' And OPBill.InvBillId='+BillId;
      AdoQry_Tmp.ExecSQL;
      //更新OPAveragePRICE数据表,供应商的移动加权平均价
      //if NeedChangeAveragePrice(AdoQry_Tmp,Copy(medt_Date.text,1,7)) then
      if True then
      begin
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:='Update OPAveragePrice Set'
          +' OPApQty=OPApQty-opb.Qty'
          +',OPApAmount=OPApAmount-opb.Amount'
          +' From (Select ItemCode,Sum(OPBillQty) As Qty,Sum(OPBillNoTaxAmount) As Amount'
          +' From OPBill'
          +' Where InvBillId='+BillId
          +' Group By ItemCode) opb'
          +' Where OPAveragePrice.VendorCode='''+Extedt_OutCode.text+''''
          +' And OPAveragePrice.ItemCode=opb.ItemCode';
        AdoQry_Tmp.ExecSQL;
      end;
      AdoQry_Body.next;
    end;

    //计算材料费InvBillline
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.Text:='Update InvInBillLine Set'
      +' InvBillNoTaxAmount=opb.Amount'
      +' From (Select InvBillId,InvBillLineNo,Sum(OPBillNoTaxAmount) As Amount'
      +' From OPBill'
      +' Where InvBillId='+BillId
      +' Group By InvBillId,InvBillLineNo) opb'
      +' Where InvInBillLine.InvBillId='+Bill_Id_1201
      +' And InvInBillLine.InvBillLineNo=opb.InvBillLineNo';
    AdoQry_Tmp.ExecSQL;
    //更新本厂的移动加权平均
   // if NeedChangeAveragePrice(AdoQry_Tmp,Copy(medt_Date.text,1,7)) then
    if True then
    begin
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:='Update AveragePrice Set'
        +' ApAmount=ApAmount+l.Amount'
        +',AveragePrice=Case When ApQty=0 Then AveragePrice'
        +' Else (ApAmount+l.Amount)/ApQty end'
        +' From (Select ItemCode,Sum(InvBillNoTaxAmount) As Amount'
        +' From InvInBillLine'
        +' Where InvBillId='+Bill_Id_1201
        +' Group By ItemCode) l'
        +' Where AveragePrice.WHCode='''+GetCode(cmbbx_WhCode.text)+''''
        +' And AveragePrice.ItemCode=l.ItemCode';
      AdoQry_Tmp.ExecSQL;
    end;
    AdoQry_Body.Connection.CommitTrans;
    //状态控制
    //-----------
    Billmemo:=Extedt_memo.text;
    BillwhCode:=getCode(cmbbx_WhCode.text);
    BillWhPositionCode:=getCode(cmbbx_WhPositionCode.text);
    BillBillType2Code:=getCode(cmbbx_BillType2Code.text);
    BilloutCode:=Extedt_OutCode.text;
    BilloutName:=lbl_OutName.Caption;
    BillLoginDate:=medt_Date.text;
    Frm_Inv_NoOrderOpIn_H.InvBillid:=Billid;
    act_insertline.Enabled :=False;
    act_Deleteline.Enabled :=False;
    act_Save.Enabled :=False;
    act_Modify.Enabled :=False;
    Billno:=BillHeadno;
    //---------
  except
    begin
      AdoQry_Body.Connection.RollBackTrans;
      if not BeforeSaveError then
      begin
        DispInfo(' 存盘不成功,请稍后再试! ',1);
        abort;
      end;
    end;
  end;
end;



procedure TFrm_Inv_NoOrderOpIn_B.DateCheck(Sender: TObject);
begin
  inherited;
  //  if(ActiveControl.Name='tlbtn_exit')then
  //  exit;
  if not whclsperiodcheck(AdoQry_tmp,getCode(cmbbx_WhCode.text),copy(medt_Date.text,1,7)) then
  begin
    medt_Date.setfocus;
    abort;
  end;
end;

procedure TFrm_Inv_NoOrderOpIn_B.Act_QuitExecute(Sender: TObject);
begin
//  inherited;
  Close;
end;

procedure TFrm_Inv_NoOrderOpIn_B.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 // inherited;
  if(Act_Save.Enabled)then
  begin
    if(DispInfo('数据有改动,需要保存吗?',2)='y')then
    begin
      Act_SaveExecute(Sender);
      Self.ModalResult:=mrOk;
    end
    else
    begin
      if(AdoQry_Head.State in [dsInsert,dsEdit])then
        AdoQry_Head.Cancel;
      Self.ModalResult:=mrCancel;
    end;
  end
  else
  begin
    if(AdoQry_Head.State in [dsInsert,dsEdit])then
      AdoQry_Head.Cancel;
    Self.ModalResult:=mrOk;
  end;

end;

procedure TFrm_Inv_NoOrderOpIn_B.cmbbx_WhCodeChange(Sender: TObject);
begin
  inherited;
  initcmbbx_WhPositionCode(getCode(cmbbx_WhCode.text));
end;

procedure TFrm_Inv_NoOrderOpIn_B.Extedt_OutCodeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=vk_F9 then
  begin
     VendorHint(sender,key,shift);
  end


end;

procedure TFrm_Inv_NoOrderOpIn_B.AdoQry_BodyAfterPost(DataSet: TDataSet);
begin
  inherited;
  IoType:=AdoQry_Body.fieldbyname('InvBillqty').asfloat;
end;

procedure TFrm_Inv_NoOrderOpIn_B.AdoQry_BodyBeforePost(DataSet: TDataSet);
begin
  inherited;
  checkIoType;
end;

procedure TFrm_Inv_NoOrderOpIn_B.Act_PreviewExecute(Sender: TObject);
begin
  //inherited;
  if Trim(cmbbx_WhCode.text)='' then
  begin
    DispInfo('仓库不能为空!',3);
    abort;
  end;
  BillPrint(AdoQry_Tmp.Connection,GetCode(cmbbx_WhCode.text),Extedt_Billno.text,Param1,ModuleCode,True,False,True,'');
end;

procedure TFrm_Inv_NoOrderOpIn_B.Act_PrintExecute(Sender: TObject);
begin
  //inherited;
  if Trim(cmbbx_WhCode.text)='' then
  begin
    DispInfo('仓库不能为空!',3);
    abort;
  end;
  BillPrint(AdoQry_Tmp.Connection,GetCode(cmbbx_WhCode.text),Extedt_Billno.text,Param1,ModuleCode,False,False,True,'');
end;

procedure TFrm_Inv_NoOrderOpIn_B.cmbbx_BillType2CodeExit(Sender: TObject);
begin
  inherited;
  if Trim(cmbbx_BillType2Code.text)='' then
  begin
    DispInfo('请选择入库类型!',1);
    twincontrol(sender).setfocus;
    abort;
  end;
end;

procedure TFrm_Inv_NoOrderOpIn_B.Act_InsertLineExecute(Sender: TObject);
begin
  if Trim(Extedt_OutCode.text)='' then
  begin
    Extedt_OutCode.SetFocus ;
    DispInfo('供应商代码不能为空!',3);
    abort;
  end;
  if (dbgrideh1.Focused) and  (not AdoQry_Body.IsEmpty)  then
  begin
    Frm_Inv_NoOrderOpIn_RealOpQty_D:=TFrm_Inv_NoOrderOpIn_RealOpQty_D.Create(Application);
    Frm_Inv_NoOrderOpIn_RealOpQty_D.SetFormParam('-1',
                                                 AdoQry_Body.fieldbyname('InvBillLineNo').AsString,
                                                 AdoQry_Body.fieldbyname('ItemCode').AsString,Vendortaxrate_Percent,'','');
    Frm_Inv_NoOrderOpIn_RealOpQty_D.InitForm(DBConnect,'Add',AdoQry_RealOpQty);
    Frm_Inv_NoOrderOpIn_RealOpQty_D.ShowModal;
    Frm_Inv_NoOrderOpIn_RealOpQty_D.Release;
  end
  else
  begin
    TFrm_Inv_NoOrderOpIn_D(Frm_Entry_Detail).setformParam1(getCode(cmbbx_WhCode.text),getCode(cmbbx_WhPositionCode.text));
    TFrm_Inv_NoOrderOpIn_D(Frm_Entry_Detail).SetFormParam('-1','','',Vendortaxrate_Percent,'','');
    TFrm_Inv_NoOrderOpIn_D(Frm_Entry_Detail).AdoQry_RealOpQty:=AdoQry_RealOpQty;
    inherited;
  end;
end;

procedure TFrm_Inv_NoOrderOpIn_B.Act_ModifyExecute(Sender: TObject);
begin
  if dbgrideh.Focused then
  begin
    Frm_Entry_Detail.SetFormParam('',Extedt_OutCode.text,currencyCode,Vendortaxrate_Percent,ExchRate,'');
    TFrm_Inv_NoOrderOpIn_D(Frm_Entry_Detail).setformParam1(getCode(cmbbx_WhCode.text),getCode(cmbbx_WhPositionCode.text));
    TFrm_Inv_NoOrderOpIn_D(Frm_Entry_Detail).AdoQry_RealOpQty:=AdoQry_RealOpQty;
    inherited;
  end
  else
  begin
    if not AdoQry_RealOpQty.Eof  then
    begin
      Frm_Inv_NoOrderOpIn_RealOpQty_D:=TFrm_Inv_NoOrderOpIn_RealOpQty_D.Create(Application);
      Frm_Inv_NoOrderOpIn_RealOpQty_D.SetFormParam(AdoQry_Body.fieldbyname('InvBillId').AsString,
                                                   AdoQry_Body.fieldbyname('InvBillLineNo').AsString,
                                                   AdoQry_Body.fieldbyname('ItemCode').AsString,'','','');
      Frm_Inv_NoOrderOpIn_RealOpQty_D.InitForm(DBConnect,'Edit',AdoQry_RealOpQty);
      Frm_Inv_NoOrderOpIn_RealOpQty_D.ShowModal;
      Frm_Inv_NoOrderOpIn_RealOpQty_D.Release;
    end;
  end;
end;

procedure TFrm_Inv_NoOrderOpIn_B.DataSourceDataChange(Sender: TObject;
  Field: TField);
begin
  inherited;
  AdoQry_RealOpQty.Filtered:=False;
  AdoQry_RealOpQty.Filter:=' InvBilllineno='''+AdoQry_Body.fieldbyname('InvBilllineno').AsString+'''';
  AdoQry_RealOpQty.Filtered:=True;
end;

procedure TFrm_Inv_NoOrderOpIn_B.Act_DeleteLineExecute(Sender: TObject);
var
  I:integer;
begin
  if (dbgrideh.Focused) and (not AdoQry_Body.IsEmpty)and
     (DispInfo(' 真的删除该物料及其所有定额的记录吗? ',2)='y') then
  begin
    with AdoQry_RealOpQty do
    begin
      First;
      while not eof do
      begin
        delete;
        next;
      end;
    end;
    AdoQry_Body.Delete;
    Act_Save.Enabled:=True;
    if (AdoQry_Body.IsEmpty)and(Status<>'PArtEdit') then
    begin
      for i:=0 to Pnl_Head.ControlCount-1 do
      begin
        if(not(Pnl_Head.Controls[i] is TLabel))then
          Pnl_Head.Controls[i].Enabled:=True;
      end;
    end;
  end
  else
  begin
    if (dbgrideh1.Focused) and
       (not AdoQry_RealOpQty.IsEmpty) and
       (DispInfo(' 真的要更改定额当前行记录吗? ',2)='y') then
    begin
      AdoQry_RealOpQty.edit;
      AdoQry_RealOpQty.fieldbyname('RealOpQtyNew').asfloat:=0;
      AdoQry_RealOpQty.fieldbyname('RealOPScrAp_PercentNew').asfloat:=0;
      AdoQry_RealOpQty.post;
    end;
  end;
end;

procedure TFrm_Inv_NoOrderOpIn_B.Act_NewExecute(Sender: TObject);
begin
  Frm_Inv_NoOrderOpIn_H.InvBilllineno:=0;
  inherited;

end;

procedure TFrm_Inv_NoOrderOpIn_B.DBGridEh1DblClick(Sender: TObject);
begin
  inherited;
  act_Modify.Execute;
end;

procedure TFrm_Inv_NoOrderOpIn_B.DBGridEh1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=vk_return then
    act_Modify.Execute;
end;

procedure TFrm_Inv_NoOrderOpIn_B.FormActivate(Sender: TObject);
begin
  inherited;
//  FreeFields:='RealOpQty,realopScrAp_Percent,RealOpQtynew,realopScrAp_Percentnew,';
end;

end.

⌨️ 快捷键说明

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