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

📄 sal_enter_othershiporder.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 5 页
字号:
          +' Left Join PayTerm  '
          +'   On Customer.CustomerPayTermCode=PayTerm.PayTermCode  '
          +' Left Join SaleType'
          +'   On Customer.CustomerSaleTypeCode=SaleType.SaleTypeCode  '
          +' Left Join Dept   '
          +'   On Customer.CustomerSaleDeptCode=Dept.DeptCode   '
          +' Left Join Employee    '
          +'   On Customer.CustomerSaleEmployeeCode=Employee.EmployeeCode  '
          +' Where CustomerCode='''+CustomerCode+'''  ';
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.clear;
  AdoQry_Tmp.SQL.text:=SqlText;
  AdoQry_Tmp.Open;
  With AdoQry_Tmp do
  begin
    if  Edt_TaxRate_Percent.Text='' then
    begin
      if (fieldbyname('CustomerTaxRate_Percent').AsInteger<>0)  then
        Edt_TaxRate_Percent.Text := fieldbyname('CustomerTaxRate_Percent').AsString
      else
        Edt_TaxRate_Percent.Text :='17';
    end;

    if Trim(Edt_SaleDeptCode.Text)='' then
    begin
      Edt_SaleDeptCode.Text := fieldbyname('CustomerSaleDeptCode').asstring;
      Edt_SaleDeptName.Text := fieldbyname('DeptName').asstring;
    end;
    if Trim(Edt_ShipModeCode.Text)='' then
    begin
      Edt_ShipModeCode.Text := fieldbyname('CustomerShipModeCode').asstring;
      Edt_ShipModeName.Text := fieldbyname('ShipModeName').asstring;
    end;
    if Trim(Edt_SaleTypeCode.Text)='' then
    begin
      Edt_SaleTypeCode.Text := fieldbyname('CustomerSaleTypeCode').asstring;
      Edt_SaleTypeName.Text :=fieldbyname('SaleTypeName').AsString;
    end;
    if Trim(Edt_SaleEmployeeCode.Text)='' then
    begin
      Edt_SaleEmployeeCode.Text := fieldbyname('CustomerSaleEmployeeCode').asstring;
      Edt_SaleEmployeeName.Text := fieldbyname('EmployeeName').asstring;
    end;
    if Trim(Edt_PayTermCode.Text)='' then
    begin
      Edt_PayTermCode.Text := fieldbyname('CustomerPayTermCode').asstring;
      Edt_SaleTermName.Text := fieldbyname('PayTermName').asstring;
    end;
    if Trim(Edt_CurrencyCode.Text)='' then
    begin
      Edt_CurrencyCode.Text := fieldbyname('CustomerCurrencyCode').asstring;
      Edt_CurrencyName.Text := fieldbyname('CurrencyName').asstring;
    end;
  end;
   SqlText:=' Select ShipAddresSCode,ShipAddressName From CustomerShipAddress '
           +' Where CustomerCode='''+CustomerCode+'''  ';
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.clear;
  AdoQry_Tmp.SQL.text:=SqlText;
  AdoQry_Tmp.Open;
  with AdoQry_Tmp do
  begin
    if Trim(Edt_ShipAddresSCode.Text)='' then
    begin
      Edt_ShipAddresSCode.Text := fieldbyname('ShipAddresSCode').asstring;
      Edt_ShipAddressName.Text := fieldbyname('ShipAddressName').asstring;
    end;
  end;

end;

procedure TFrm_Sal_Enter_OtherShipOrder.Edt_CustomerCodeEnter(
  Sender: TObject);
begin
  inherited;
  Enter_CustomerCode:=Trim(Edt_CustomerCode.text);
end;

procedure TFrm_Sal_Enter_OtherShipOrder.Edt_ShipAddresSCodeButtonClick(
  Sender: TObject);
begin
  inherited;
 CommOnHint(Sender,AdoQry_Tmp,'ShipAddressName','发货地址名称','ShipAddresSCode',
             '发货地址代号',' CustomerShipAddress ',' CustomerCode= '''+Edt_CustomerCode.Text+'''');

end;

procedure TFrm_Sal_Enter_OtherShipOrder.Edt_PayTermCodeButtonClick(
  Sender: TObject);
begin
  inherited;
 CommOnHint(Sender,AdoQry_Tmp,'PayTermName','付款条款名称','PayTermCode',
             '付款条款代号',' PayTerm ');
end;

procedure TFrm_Sal_Enter_OtherShipOrder.Edt_ShipModeCodeButtonClick(
  Sender: TObject);
begin
  inherited;
 CommOnHint(Sender,AdoQry_Tmp,'ShipModeName','发货方式名称','ShipModeCode',
             '发货方式代号',' ShipMode ');
end;

procedure TFrm_Sal_Enter_OtherShipOrder.Edt_SaleTypeCodeButtonClick(
  Sender: TObject);
begin
  inherited;
  CommonHint(Sender,AdoQry_Body,'SaleTypeName','销售类型描述','SaleTypeCode','销售类型代码',
            'SaleType');
end;

procedure TFrm_Sal_Enter_OtherShipOrder.updateqty(Addorreduce: integer);
var enoughBatch:boolean;
    enoughCurrent:boolean;
    Book:string;
begin
  Book:=AdoQry_Body.BookmArk;
  AdoQry_Body.First;
  while not AdoQry_Body.Eof do
    begin
      enoughBatch:=enoughBatchInv(AdoQry_Body.fieldbyname('Batchno').asstring,Edt_WhCode.Text,Edt_WhPositionCode.Text,AdoQry_Body.fieldbyname('Shipqty').asfloat);
      enoughCurrent:=enoughCurrentInv(Edt_WhCode.Text,Edt_WhPositionCode.Text,AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('Shipqty').asfloat);
      if AdoQry_Body.fieldbyname('Batchno').asstring<>'' then
        if (Addorreduce=0) and (not enoughBatch) then
          begin
           DispInfo('第'+inttostr(AdoQry_Body.recno)+'行'+quotedstr(AdoQry_Body.fieldbyname('ItemCode').asstring)+'物料'+Edt_WhName.Text+Edt_WhPositionName.Text+'批次库存不够!',1);
           abort;
          end;
      if (Addorreduce=0 ) and (not enoughCurrent) then
         begin
           DispInfo('第'+inttostr(AdoQry_Body.recno)+'行'+quotedstr(AdoQry_Body.fieldbyname('ItemCode').asstring)+'物料'+Edt_WhName.Text+Edt_WhPositionName.Text+'库存不够!',1);
           abort;
         end;
      if AdoQry_Body.fieldbyname('Batchno').asstring<>'' then
         reduceBatchInv(AdoQry_Body.fieldbyname('Batchno').asstring,Edt_WhCode.Text,Edt_WhPositionCode.Text,AdoQry_Body.fieldbyname('Shipqty').asfloat,1);
       reduceCurrentInv(Edt_WhCode.Text,Edt_WhPositionCode.Text,AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('Shipqty').asfloat,1);
       reduceItemqty(AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('Shipqty').asfloat,1);
       //saveSaleOrderLineHistory(dbconnect,AdoQry_Body.fieldbyname('slono').asstring,AdoQry_Body.fieldbyname('slolineno').asinteger,userCode,1);
       updateslolineqty(AdoQry_Body.fieldbyname('slono').asstring,AdoQry_Body.fieldbyname('slolineno').asinteger,AdoQry_Body.fieldbyname('Shipqty').asfloat,0);
      AdoQry_Body.Next;
    end;
AdoQry_Body.BookmArk:=Book;
end;

function TFrm_Sal_Enter_OtherShipOrder.enoughBatchInv(Batchno, whCode,
  WhPositionCode: string; qty: real): boolean;
var AdoQry:TAdoQuery;
    sqltext:string;
begin
  Result:=False;
  AdoQry:=TAdoQuery.Create(self);
  AdoQry.Connection:=dbconnect;
  sqltext:='select InvQty from BatchCurrentInv '
          +' where  whCode='+quotedstr(whCode)
          +'   and  WhPositionCode='+quotedstr(WhPositionCode)
          +'   and Batchno='+quotedstr(Batchno);
   try
    Executesql(AdoQry,sqltext,0);
    if AdoQry.RecordCount>0 then
     if AdoQry.fieldbyname('InvQty').asfloat>=qty then
       Result:=True;
   finally
    AdoQry.Free;
   end;
end;

function TFrm_Sal_Enter_OtherShipOrder.enoughCurrentInv(whCode,
  WhPositionCode, ItemCode: string; qty: real): boolean;
var AdoQry:TAdoQuery;
    sqltext:string;
begin
  Result:=False;
  AdoQry:=TAdoQuery.Create(self);
  AdoQry.Connection:=dbconnect;
  sqltext:='select onhandInv from CurrentInv '
          +' where whCode='+quotedstr(whCode)
          +'  and  WhPositionCode='+quotedstr(WhPositionCode)
          +'  and  ItemCode='+quotedstr(ItemCode);
   try
    Executesql(AdoQry,sqltext,0);
    if AdoQry.RecordCount>0 then
     if AdoQry.fieldbyname('onhandInv').asfloat>=qty then
       Result:=True;
   finally
    AdoQry.Free;
   end;
end;

procedure TFrm_Sal_Enter_OtherShipOrder.reduceBatchInv(Batchno, whCode,
  WhPositionCode: string; qty: real; Addorreduce: integer);
var AdoQry:TAdoQuery;
    sqltext:string;
begin
  AdoQry:=TAdoQuery.Create(self);
  AdoQry.Connection:=dbconnect;
  sqltext:='update BatchCurrentInv '
          +' set InvQty=InvQty'+iifValue(Addorreduce=0,'+','-')+floattostr(qty)
          +' where   Batchno='+quotedstr(Batchno)
          +'  and    whCode='+quotedstr(whCode)
          +'  and    WhPositionCode='+quotedstr(WhPositionCode);
   try
    Executesql(AdoQry,sqltext,1);
   finally
    AdoQry.Free;
   end;
end;

procedure TFrm_Sal_Enter_OtherShipOrder.reduceCurrentInv(whCode,
  WhPositionCode, ItemCode: string; qty: real; Addorreduce: integer);
var AdoQry:TAdoQuery;
    sqltext:string;
begin
  AdoQry:=TAdoQuery.Create(self);
  AdoQry.Connection:=dbconnect;
  sqltext:='update  CurrentInv '
          +'  set onhandInv=onhandInv'+iifValue(Addorreduce=0,'+','-')+floattostr(qty)
          +' where whCode='+quotedstr(whCode)
          +'  and  WhPositionCode='+quotedstr(WhPositionCode)
          +'  and  ItemCode='+quotedstr(ItemCode);
   try
    Executesql(AdoQry,sqltext,1);
   finally
    AdoQry.Free;
   end;
end;

procedure TFrm_Sal_Enter_OtherShipOrder.reduceItemqty(ItemCode: string;
  qty: real; Addorreduce: integer);
var AdoQry:TAdoQuery;
    sqltext:string;
begin
  AdoQry:=TAdoQuery.Create(self);
  AdoQry.Connection:=dbconnect;
  sqltext:='update Item'
          +'  set  CurrentonhandInv=CurrentonhandInv'+iifValue(Addorreduce=0,'+','-')+floattostr(qty)
          +' where ItemCode='+quotedstr(ItemCode);

   try
    Executesql(AdoQry,sqltext,1);
   finally
    AdoQry.Free;
   end;
end;

procedure TFrm_Sal_Enter_OtherShipOrder.updateslolineqty(slono: string;
  slolineno: integer; qty: real; Addorreduce: integer);
var AdoQry:TAdoQuery;
    sqltext:string;
begin
  AdoQry:=TAdoQuery.Create(self);
  AdoQry.Connection:=dbconnect;
  sqltext:='update sa_SaleOrderline'
          +'  set  Shipqty=Shipqty'+iifValue(Addorreduce=0,'+','-')+floattostr(qty)+','
          +'       PrepareShipqty=PrepareShipqty'+iifValue(Addorreduce=0,'-','+')+floattostr(qty)
          +' where slono='+quotedstr(slono)
          +'   and slolineno='+inttostr(slolineno);

   try
    Executesql(AdoQry,sqltext,1);
   finally
    AdoQry.Free;
   end;
end;

procedure TFrm_Sal_Enter_OtherShipOrder.Act_QuitExecute(Sender: TObject);
begin
  //inherited;
  if(Act_Save.Enabled)then
  begin
    if(DispInfo('数据有改动,需要保存吗?',2)='y')then
    begin
      Act_Save.OnExecute(act_Save);
      if(AdoQry_Head.State in [dsEdit,dsInsert])then
        AdoQry_Head.Post;
      Self.ModalResult:=mrOk;
    end
    else
    begin
      if(AdoQry_Head.State in [dsInsert,dsEdit])then
        AdoQry_Head.Cancel;
    end;
  end
  else
  begin
    if(AdoQry_Head.State in [dsInsert])then
      AdoQry_Head.Cancel
    else if(AdoQry_Head.State in [dsEdit])then
      AdoQry_Head.Post;
    Self.ModalResult:=mrOk;
  end;
  Act_Save.Enabled := False;
  Close;

end;

procedure TFrm_Sal_Enter_OtherShipOrder.Edt_WhCodeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 120 then
  CommOnHint(Sender,AdoQry_Tmp,'WhName','仓库名称','WhCode',
             '仓库代码',' Warehouse ');
  
end;

procedure TFrm_Sal_Enter_OtherShipOrder.Edt_WhCodeButtonClick(
  Sender: TObject);
begin
  inherited;
  CommOnHint(Sender,AdoQry_Tmp,'WhName','仓库名称','WhCode',
             '仓库代码',' Warehouse ');

end;

procedure TFrm_Sal_Enter_OtherShipOrder.Edt_WhCodeExit(Sender: TObject);
begin
  inherited;
  if ActiveControl.Name ='ToolButton4'  then exit;
  if Trim(Edt_WhCode.Text)='' then exit;
  ExecuteSql(AdoQry_Tmp,'Select * from Warehouse '
            +'  where WhCode='+QuotedStr(Edt_WhCode.Text),0);
  if AdoQry_Tmp.RecordCount=0 then 
  begin
    DispInfo('仓库代码错误!',3);
    Edt_WhCode.SetFocus;
    abort;
 

⌨️ 快捷键说明

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