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

📄 acr510_02.pas.svn-base

📁 一个用Delphi开发的ERP软件
💻 SVN-BASE
📖 第 1 页 / 共 4 页
字号:
      begin
        //取得料品的基本信息
        AItemInfo.ItemNo:=adsInv150.FieldByName('FItemNo').AsInteger;
        AItemInfo.ItemID:=adsInv150.FieldByName('FItemID').AsString;
        AItemInfo.ItemName:=adsInv150.FieldByName('FItemName').AsString;
        AItemInfo.ItemSpec:=adsInv150.FieldByName('FItemSpec').AsString;
        AItemInfo.UnitNo:=adsInv150.FieldByName('FUnitNo').AsInteger;
        AItemInfo.UnitID:=adsInv150.FieldByName('FUnitID').AsString;
        AItemInfo.UnitName:=adsInv150.FieldByName('FUnitName').AsString;
        AItemInfo.OrderNo:=adsInv150.FieldByName('FCode').AsString;       //来源单号
        AItemInfo.LineNo:=adsInv150.FieldByName('FNo').Value;             //来源行号
        //取得价格信息
        APriceInfo.StdPrice:=adsInv150.FieldByName('FPrice').Value;       //销售单价
        APriceInfo.OrderAmt:=adsInv150.FieldByName('FAmount').Value;      //销售金额
        APriceInfo.TaxRate:=adsInv150.FieldByName('FTaxRate').Value;      //销售税率
        APriceInfo.TaxAmount:=adsInv150.FieldByName('FTaxAmount').Value;  //销售税额
        APriceInfo.DisAmt:=adsInv150.FieldByName('FDisAmt').Value;        //折扣金额
        //取得定单信息
        AOrderInfo.OrderQty:=adsInv150.FieldByName('FQty').Value;         //销售数量
        AOrderInfo.InvAmount:=adsInv150.FieldByName('FInvAmount').Value;  //发票金额
        //添加订单信息
        AddItemLine(AOrderInfo,APriceInfo,AItemInfo,adsAcr510B,'ADD');
        adsInv150.Edit;
        adsInv150.FieldByName('FSel').Value:=0;
        adsInv150.Post;
      end;
      adsInv150.EnableControls;
    end;
    wwDBGrid1.OnUpdateFooter:=wwDBGrid1UpdateFooter;
    AIsChanged:=True;
    ABusy:=False;
    wwDBGrid1UpdateFooter(wwDBGrid1);
    Screen.Cursor:=crDefault;
  end;
end;

procedure TAcr510_02Form.AddItemLine(AOrderInfo: TOrderInfo;  APriceInfo:TPriceInfo;
  AItemInfo: TItemInfo; ADataSet: TADODataSet; AType: String);
begin
  //取得产品价格
  if not (ADataSet.State in [dsInsert,dsEdit]) then
    if (ADataSet.IsEmpty) or (AType='ADD') then ADataSet.Append else ADataSet.Edit;
  ADataSet.FieldByName('FItemID').Value:=AItemInfo.ItemID;
  ADataSet.FieldByName('FItemName').Value:=AItemInfo.ItemName;
  ADataSet.FieldByName('FItemSpec').Value:=AItemInfo.ItemSpec;
  ADataSet.FieldByName('FUnitName').Value:=AItemInfo.UnitName;
  ADataSet.FieldByName('FOrderQty').Value:=AOrderInfo.OrderQty;
  ADataSet.FieldByName('FOrderPrice').Value:=APriceInfo.StdPrice;
  ADataSet.FieldByName('FOrderAmount').Value:=APriceInfo.OrderAmt;
  ADataSet.FieldByName('FDisAmt').Value:=APriceInfo.DisAmt;
  ADataSet.FieldByName('FItemNo').Value:=AItemInfo.ItemNo;
  ADataSet.FieldByName('FOrder').Value:=AItemInfo.OrderNo;
  ADataSet.FieldByName('FLineNo').Value:=AItemInfo.LineNo;

  ADataSet.FieldByName('FQty').Value:=ADataSet.FieldByName('FOrderQty').Value;
  ADataSet.FieldByName('FAmount').Value:=ADataSet.FieldByName('FOrderAmount').Value-APriceInfo.DisAmt;
  ADataSet.FieldByName('FPrice').Value:=ADataSet.FieldByName('FAmount').Value/ADataSet.FieldByName('FQty').Value;

  ADataSet.FieldByName('FTaxRate').Value:=APriceInfo.TaxRate;
  ADataSet.FieldByName('FTaxAmt').Value:=APriceInfo.TaxAmount;
  ADataSet.FieldByName('FInvAmount').Value:=AOrderInfo.InvAmount;
  ADataSet.FieldByName('FAcrAmt').Value:=ADataSet.FieldByName('FAmount').Value+ADataSet.FieldByName('FTaxAmt').Value;

  if AType='UPD' then Exit;
  ADataSet.Post;
end;

procedure TAcr510_02Form.adsAcr510BNewRecord(DataSet: TDataSet);
begin
  inherited;
  //设定行的初始值
  ALastNo:=ALastNo+1;
  adsAcr510BFNo.Value:=ALastNo;
end;

procedure TAcr510_02Form.cbCurrChange(Sender: TObject);
begin
  inherited;
  qryGld100.Locate('G100_003',cbCurr.Text,[]);
  edtRate.Text:=qryGld100.FieldByName('G100_005').AsString;
  adsAcr510B.Close;
  adsAcr510B.CreateDataSet;
  AIsChanged:=True;
  wwDBGrid1UpdateFooter(wwDBGrid1);
end;

procedure TAcr510_02Form.wwDBGrid1ColExit(Sender: TObject);
begin
  inherited;
  if wwDBGrid1.GetActiveField.FieldName='FQty' then
  begin
    SetQty;
  end else
  if wwDBGrid1.GetActiveField.FieldName='FPrice' then
  begin
    SetPrice;
  end;
  if wwDBGrid1.GetActiveField.FieldName='FAmount' then
  begin
    SetAmount;
  end;
  if wwDBGrid1.GetActiveField.FieldName='FOrderQty' then
  begin
    SetDefault;
  end;
  if wwDBGrid1.GetActiveField.FieldName='FTaxRate' then
  begin
    SetTaxRate;
  end;
end;

procedure TAcr510_02Form.SetPrice;
begin
  if adsAcr510BFPrice.AsFloat>adsAcr510BFOrderPrice.AsFloat then
  begin
    ShowMsg('UMS10000665');   //发票单价不能大于销售单价,请重新输入
    Exit;
  end else
  begin
    if not (adsAcr510B.State in [dsInsert,dsEdit]) then Exit;
    wwDBGrid1.ColumnByName('FAmount').ReadOnly:=False;
    wwDBGrid1.ColumnByName('FTaxAmt').ReadOnly:=False;
    wwDBGrid1.ColumnByName('FAcrAmt').ReadOnly:=False;
    adsAcr510BFAmount.Value:=adsAcr510BFQty.Value*adsAcr510BFPrice.Value;
    adsAcr510BFTaxAmt.Value:=adsAcr510BFAmount.Value*adsAcr510BFTaxRate.Value;
    adsAcr510BFAcrAmt.Value:=adsAcr510BFAmount.Value+adsAcr510BFTaxAmt.Value;
    wwDBGrid1.ColumnByName('FTaxAmt').ReadOnly:=True;
    wwDBGrid1.ColumnByName('FAcrAmt').ReadOnly:=True;
  end;
end;

procedure TAcr510_02Form.SetQty;
begin
  if adsAcr510BFQty.AsFloat>adsAcr510BFOrderQty.AsFloat then
  begin
    ShowMsg('UMS10000666');   //发票数量不能大于销售数量,请重新输入
    Exit;
  end else
  begin
    if not (adsAcr510B.State in [dsInsert,dsEdit]) then Exit;
    wwDBGrid1.ColumnByName('FAmount').ReadOnly:=False;
    wwDBGrid1.ColumnByName('FTaxAmt').ReadOnly:=False;
    wwDBGrid1.ColumnByName('FAcrAmt').ReadOnly:=False;
    adsAcr510BFAmount.Value:=adsAcr510BFQty.Value*adsAcr510BFPrice.Value;
    adsAcr510BFTaxAmt.Value:=adsAcr510BFAmount.Value*adsAcr510BFTaxRate.Value;
    adsAcr510BFAcrAmt.Value:=adsAcr510BFAmount.Value+adsAcr510BFTaxAmt.Value;
    adsAcr510BFTaxAmt.ReadOnly:=True;
    adsAcr510BFAcrAmt.ReadOnly:=True;
    wwDBGrid1.ColumnByName('FTaxAmt').ReadOnly:=True;
    wwDBGrid1.ColumnByName('FAcrAmt').ReadOnly:=True;
  end;
end;

procedure TAcr510_02Form.wwDBGrid1Enter(Sender: TObject);
begin
  inherited;
  OnKeyDown:=nil;
end;

procedure TAcr510_02Form.wwDBGrid1Exit(Sender: TObject);
begin
  inherited;
  OnKeyDown:=AKeyEvent;
end;

procedure TAcr510_02Form.SetDefault;
begin
  //
end;

procedure TAcr510_02Form.wwDBGrid1UpdateFooter(Sender: TObject);
var
  AAmount,ATaxAmt,AAcrAmt:Double;
begin
  inherited;
  //发票金额 FAmount  发票税额 FTaxAmt  应收金额 FAcrAmt
  if not AIsChanged then Exit;
  AAmount:=0;
  ATaxAmt:=0;
  AAcrAmt:=0;
  ADODataSet1.Clone(adsAcr510B);
  ADODataSet1.DisableControls;
  ADODataSet1.First;
  while not ADODataSet1.Eof do
  begin
    AAmount:=AAmount+StrToFloatA(FloatToStrF(ADODataSet1.FieldByName('FAmount').AsFloat,ffNumber,18,2));
    ATaxAmt:=ATaxAmt+StrToFloatA(FloatToStrF(ADODataSet1.FieldByName('FTaxAmt').AsFloat,ffNumber,18,2));
    AAcrAmt:=AAcrAmt+StrToFloatA(FloatToStrF(ADODataSet1.FieldByName('FAcrAmt').AsFloat,ffNumber,18,2));
    ADODataSet1.Next;
  end;
  ADODataSet1.EnableControls;
  wwDBGrid1.ColumnByName('FItemID').FooterValue:=GetDBString('COM00004002')+FloatToStrF(ADODataSet1.RecordCount,ffNumber,18,0);  //记录总数
  wwDBGrid1.ColumnByName('FAmount').FooterValue:=FloatToStrF(AAmount,ffNumber,18,2);
  wwDBGrid1.ColumnByName('FTaxAmt').FooterValue:=FloatToStrF(ATaxAmt,ffNumber,18,2);
  wwDBGrid1.ColumnByName('FAcrAmt').FooterValue:=FloatToStrF(AAcrAmt,ffNumber,18,2);

  edtAmount.Text:=FloatToStrF(AAmount,ffNumber,18,2);
  edtRevenue.Text:=FloatToStrF(ATaxAmt,ffNumber,18,2);
  edtReceive.Text:=FloatToStrF(AAcrAmt,ffNumber,18,2);

end;

procedure TAcr510_02Form.SetDBGridA;
var
  I:Integer;
begin
  for I:=0 to wwDBGrid1.Selected.Count-1 do
  begin
    wwDBGrid1.Columns[I].ReadOnly:=True;
  end;
  wwDBGrid1.ColumnByName('FQty').ReadOnly:=False;
  wwDBGrid1.ColumnByName('FPrice').ReadOnly:=False;
  wwDBGrid1.ColumnByName('FTaxRate').ReadOnly:=False;
  wwDBGrid1.ColumnByName('FRemark').ReadOnly:=False;
  wwDBGrid1.Refresh;
end;


procedure TAcr510_02Form.edtCustExit(Sender: TObject);
begin
  inherited;
//客户编号
  if trim(edtCust.Text)='' then Exit;
  if qryOrd150.Locate('O150_002',edtCust.Text,[]) then
  begin
    GetCustPlaceInfo;
  end else
  begin
    ShowMsg('UMS10000667');  //输入的客户编号无效,请重新输入
    edtCustName.Text:='';
    edtPhone.Text:='';
    edtAddress.Text:='';
    edtContact.Text:='';
    edtCust.SetFocus;
    adsAcr510B.Close;
    adsAcr510B.CreateDataSet;
    Abort;
  end;
end;

procedure TAcr510_02Form.Action1Execute(Sender: TObject);
begin
  inherited;
  //取消
  if ADOQuery1.IsEmpty then
  begin
    ShowMsg('UMS10000668');  //表记录为空,操作无效
    Abort;
  end;
  if not (ADOQuery1A510A_003.Value in [1]) then
  begin
    ShowMsg('UMS10000669');  //仅新增状态的销售发票可以作废
    Abort;
  end;
  ADOQuery1.Edit;
  ADOQuery1A510A_003.Value:=1;
  ADOQuery1.Post;
  ActRefresh.Execute;
  ShowMsg('UMS10000670');  //销售发票状态已成功设置为作废状态
end;

procedure TAcr510_02Form.SetAmount;
begin
  if adsAcr510BFAmount.AsFloat>adsAcr510BFOrderAmount.Value-adsAcr510BFDisAmt.Value then
  begin
    ShowMsg('UMS10000671');   //发票金额不能大于销售金额和折扣金额之差销售单价,请重新输入
    Exit;
  end else
  begin
    if not (adsAcr510B.State in [dsInsert,dsEdit]) then Exit;
    wwDBGrid1.ColumnByName('FPrice').ReadOnly:=False;
    wwDBGrid1.ColumnByName('FQty').ReadOnly:=False;
    wwDBGrid1.ColumnByName('FTaxAmt').ReadOnly:=False;
    wwDBGrid1.ColumnByName('FAcrAmt').ReadOnly:=False;
    adsAcr510BFPrice.Value:=adsAcr510BFOrderPrice.Value;
    adsAcr510BFQty.Value:=adsAcr510BFOrderAmount.Value/adsAcr510BFPrice.Value;
    adsAcr510BFTaxAmt.Value:=adsAcr510BFAmount.Value*adsAcr510BFTaxRate.Value;
    adsAcr510BFAcrAmt.Value:=adsAcr510BFAmount.Value+adsAcr510BFTaxAmt.Value;
    wwDBGrid1.ColumnByName('FAcrAmt').ReadOnly:=True;
  end;
end;

procedure TAcr510_02Form.SetTaxRate;
begin
  if not (adsAcr510B.State in [dsInsert,dsEdit]) then Exit;
  wwDBGrid1.ColumnByName('FTaxAmt').ReadOnly:=False;
  wwDBGrid1.ColumnByName('FAcrAmt').ReadOnly:=False;
  adsAcr510BFTaxAmt.Value:=adsAcr510BFAmount.Value*adsAcr510BFTaxRate.Value;
  adsAcr510BFAcrAmt.Value:=adsAcr510BFTaxAmt.Value+adsAcr510BFAmount.Value;
  wwDBGrid1.ColumnByName('FTaxAmt').ReadOnly:=True;
  wwDBGrid1.ColumnByName('FAcrAmt').ReadOnly:=True;
end;

initialization
  RegisterClass(TAcr510_02Form);
finalization
  UnRegisterClass(TAcr510_02Form);
end.

⌨️ 快捷键说明

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