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

📄 sal_enter_shiporder.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    DispInfo('销售税率不能为空!',3);
    Edt_TaxRate_Percent.SetFocus;
    Abort;
  end;

  TaxRate_Percent:=Edt_TaxRate_Percent.Text;
  CustomerCode:=Edt_CustomerCode.Text;
  inherited;
//  Edt_InvBillNo.Enabled:=False;
end;

procedure TFrm_Sal_Enter_ShipOrder.Edt_DeptCodeExit(Sender: TObject);
begin
  inherited;
  if Edt_DeptCode.Text <> '' then
  begin
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.Text:=' Select DeptCode,DeptName from Dept '
                        +'          where DeptCode= '''+Edt_DeptCode.Text+''' ';
    AdoQry_Tmp.Open;
    if  not AdoQry_Tmp.Eof then
      Edt_SaleDeptName.Text := AdoQry_Tmp.fieldbyname('DeptName').AsString
    else
    begin
      DispInfo('销售部门代码错误,请重新输入',1);
      TWinControl(Sender).SetFocus;
      Abort;
    end;
  end
  else
  begin
    Edt_SaleDeptName.Text:='';
  end;

end;

procedure TFrm_Sal_Enter_ShipOrder.Edt_CustomerCodeExit(Sender: TObject);
begin
  inherited;
  If Edt_CustomerCode.Text = '' Then
  begin
{    DispInfo('客户代码不能为空!',3);
    TWincontrol(Sender).SetFocus;
    Abort;}
  end
  else
  begin
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.Text:=' Select CustomerCode,CustomerName from Customer '
                        +'          where CustomerCode= '''+Edt_CustomerCode.Text+''' ';
    AdoQry_Tmp.Open;
    Edt_CustomerName.Text := AdoQry_Tmp.fieldbyname('CustomerName').AsString;
  end;
end;

procedure TFrm_Sal_Enter_ShipOrder.Edt_SaleEmployeeCodeExit(
  Sender: TObject);
begin
  inherited;
  if  Edt_SaleEmployeeCode.Text <>'' then
  begin
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.Text:=' Select EmployeeCode,EmployeeName from Employee '
                        +'          where EmployeeCode= '''+Edt_SaleEmployeeCode.Text+''' ';
    AdoQry_Tmp.Open;
    if not AdoQry_Tmp.Eof then
    begin
      Edt_SaleEmployeeName.Text := AdoQry_Tmp.fieldbyname('EmployeeName').AsString;
    end
    else
    begin
      DispInfo('销售员代码错误,请重新输入',1);
      TWinControl(Sender).SetFocus;
      Abort;
    end;
  end
  else
    Edt_SaleEmployeeName.Text:='';
end;

procedure TFrm_Sal_Enter_ShipOrder.Edt_CurrencyCodeExit(Sender: TObject);
begin
  inherited;
  IF Trim(Edt_CurrencyCode.Text)<>'' Then
     CurrencyCodeCheck(Sender);
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.clear;
  AdoQry_Tmp.SQL.Text:=' Select CurrencyCode,CurrencyName,IsMaster from Currency '
                      +'          where CurrencyCode= '''+Edt_CurrencyCode.Text+''' ';
  AdoQry_Tmp.Open;
  Edt_CurrencyName.Text := AdoQry_Tmp.fieldbyname('CurrencyName').AsString;
  If AdoQry_Tmp.fieldbyname('IsMaster').AsInteger=1 then Exit;{如果是本位币则不用判断是否有外币汇率资料}
  ExecuteSql(AdoQry_Tmp,' select * from ExchRate  '
                       + '  where CurrencyCode= '+QuotedStr(Edt_CurrencyCode.Text)
                       + '    and ExchMonth= '+QuotedStr(copy(Medt_CreateDate.Text,1,7)),0);
  if AdoQry_tmp.RecordCount=0 then 
  begin
    DispInfo('没有该货币'+Copy(Medt_CreateDate.Text,1,7)+'月的外币汇率!',3);
    If Edt_CurrencyCode.CanFocus then  Edt_CurrencyCode.SetFocus;
    Abort;    
  end;

  ExchRate := AdoQry_Tmp.fieldbyname('ExchRate').AsFloat;
    
end;

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

end;

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

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

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

procedure TFrm_Sal_Enter_ShipOrder.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('InvBillQty').asfloat);
      enoughCurrent:=enoughCurrentInv(Edt_WhCode.Text,Edt_WhPositionCode.Text,AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('InvBillQty').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('InvBillQty').asfloat,1);
       reduceCurrentInv(Edt_WhCode.Text,Edt_WhPositionCode.Text,AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('InvBillQty').asfloat,1);
       reduceItemqty(AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('InvBillQty').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('InvBillQty').asfloat,0);
      AdoQry_Body.Next;
    end;
  AdoQry_Body.BookmArk:=Book;
end;

function TFrm_Sal_Enter_ShipOrder.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;

function TFrm_Sal_Enter_ShipOrder.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;

procedure TFrm_Sal_Enter_ShipOrder.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_ShipOrder.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_ShipOrder.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_ShipOrder.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=IsNull(ShipQty,0)'+iifValue(Addorreduce=0,'+','-')+floattostr(qty)+','
          +'       PrepareShipQty=IsNull(PrepareShipQty,0)'+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_ShipOrder.FormActivate(Sender: TObject);
begin
  inherited;
//  act_Save.Enabled:=True;
  if CurrentFormStatus='ReadOnly' then act_Save.Enabled:=False;
  if CurrentFormStatus='Edit' then act_Save.Enabled:=False;
  if CurrentFormStatus='Add'  then Act_Save.

⌨️ 快捷键说明

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