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

📄 stedslgoodsoutcost.pas

📁 详细的ERP设计资料
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit STEdSLGoodsOutCost;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, BaseVoucherEditA, Menus, ActnList, DB, ComCtrls, StdCtrls, Mask,
  DBCtrls, ExtCtrls, ToolWin, Grids, DBGrids, QLDBGrid, ADODB, GEdit,
  QLDBLkp, Buttons, Types,QuickRpt;



type
  TSTEdSLGoodsOutCostForm = class(TBaseVoucherEditAForm)
    Label2: TLabel;
    Label3: TLabel;
    ClientName: TADODataSet;
    EmployeeName: TADODataSet;
    GoodName: TADODataSet;
    Label5: TLabel;
    PackUnit: TADODataSet;
    dsPackUnit: TDataSource;
    DSClientName: TDataSource;
    DSEmployeeName: TDataSource;
    LookupEmployee: TQLDBLookupComboBox;
    TempAds: TADODataSet;
    adsMaster: TADODataSet;
    adsDetail: TADODataSet;
    adsDetailID: TAutoIncField;
    adsDetailMasterID: TIntegerField;
    adsDetailGoodsID: TIntegerField;
    adsDetailQuantity: TBCDField;
    adsDetailPackUnitID: TIntegerField;
    adsDetailPriceBase: TBCDField;
    adsDetailAmount: TBCDField;
    adsDetailGoalQuantity: TBCDField;
    adsDetailGoalUnitID: TIntegerField;
    adsMasterID: TAutoIncField;
    adsMasterCreateDate: TDateTimeField;
    adsMasterCreateUserID: TIntegerField;
    adsMasterRecordState: TStringField;
    adsMasterDate: TDateTimeField;
    adsMasterCode: TStringField;
    adsMasterClientID: TIntegerField;
    adsMasterBillMode: TStringField;
    adsMasterPeriodID: TIntegerField;
    adsMasterClearDate: TDateTimeField;
    adsMasterMemo: TStringField;
    adsMasterSundryFee: TBCDField;
    Label8: TLabel;
    adsMasterClientName: TStringField;
    DiscountMode: TAction;
    adsMasterEmployeeID: TIntegerField;
    adsMasterApportion: TStringField;
    adsMasterDeliver: TStringField;
    adsMasterOriginID: TIntegerField;
    adsMasterOriginTable: TStringField;
    adsMasterBillAffix: TBytesField;
    adsDetailMemo: TStringField;
    adsMasterBrief: TStringField;
    BriefComboBox: TDBComboBox;
    Label9: TLabel;
    adsDetailGoodsSpec: TStringField;
    adsGoodsSpec: TADODataSet;
    dsGoodsSpec: TDataSource;
    adsMasterEmployee: TStringField;
    StockQuerry: TAction;
    adsMasterWarehouseID: TIntegerField;
    adsWarehouse: TADODataSet;
    dsWarehouse: TDataSource;
    ClientQLDBLookup: TQLDBLookupComboBox;
    adsMasterModeDC: TIntegerField;
    adsMasterModeC: TIntegerField;
    DBEdit2: TDBEdit;
    Label1: TLabel;
    adsDetailQuantityPcs: TBCDField;
    adsDetailDiscount: TBCDField;
    adsDetailTaxAmount: TBCDField;
    adsDetailSundryFee: TBCDField;
    adsDetailPackunit: TStringField;
    FeeAportPopupMenu: TPopupMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    GoalUnit: TADODataSet;
    dsGoalUnit: TDataSource;
    adsDetailGoalUnit: TStringField;
    adsDetailGoodsName: TStringField;
    Label4: TLabel;
    DBEdit3: TDBEdit;
    ADOQuery: TADOQuery;
    Label7: TLabel;
    DBEdit5: TDBEdit;
    Label6: TLabel;
    DBEdit4: TDBEdit;
    SpeedButton1: TSpeedButton;
    TpcPanel: TPanel;
    BitBtn1: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn4: TBitBtn;
    SpeedButton2: TSpeedButton;
    DBEdit1: TDBEdit;
    TempQry: TADOQuery;
    ClearSundryFeeAct: TMenuItem;
    adsDetailPriceCost: TBCDField;
    Label10: TLabel;
    DBEdit6: TDBEdit;
    adsMasterLastCostDate: TDateTimeField;
    adsMasterIndirectFee: TBCDField;
    adsDetailPriceGoal: TBCDField;
    adsDetailOriginID: TIntegerField;
    adsDetailOriginTable: TStringField;
    SpeedButton3: TSpeedButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure ClearSundryFeeActClick(Sender: TObject);
    procedure adsDetailSundryFeeChange(Sender: TField);
    procedure SaveActionExecute(Sender: TObject);
    procedure adsDetailPriceGoalChange(Sender: TField);

  private
    { Private declarations }
   LastDate :TDatetime;
  public
    { Public declarations }
    procedure Open(VoucherID: Integer); override;
    procedure New; override;
  end;

var
  STEdSLGoodsOutCostForm: TSTEdSLGoodsOutCostForm;

implementation

uses CommonDM, WSUtils, WSSecurity, QLDBAgg;
{$R *.dfm}
procedure TSTEdSLGoodsOutCostForm.New;
begin
  inherited;
  TempQry.Close;
  TempQry.sql.text :='select max(ClearDate) as ClearDate from '
    +' STSLGoodsOutCostMaster  where RecordState<>'
    +Quotedstr('删除')+' and RecordState<>'+Quotedstr('作废');
  TempQry.Open;

  if TempQry.FieldByName('ClearDate').IsNull  then   LastDate := EncodeDate(2001,01,01)
    else LastDate :=TempQry.FieldByName('ClearDate').AsDateTime ;

  adsMaster.FieldByName('LastCostDate').AsDateTime :=LastDate;
  adsMaster.FieldByName('Date').AsDateTime :=Date;
  adsMaster.FieldByName('ClearDate').AsDateTime :=Date;
  adsMaster.FieldByName('Code').AsString:=GetMaxCode('Code','STSLGoodsOutCostMaster',number);
  adsMaster.FieldByName('CreateUserID').AsInteger :=Guarder.UserID;
  adsMaster.FieldByName('BillMode').AsString:='销售成本核算';
  adsMaster.FieldByName('ModeDC').AsInteger :=1;
  adsMaster.FieldByName('ModeC').AsInteger :=1;
  adsMaster.FieldByName('OriginTable').AsString:='STSLGoodsOutCostMaster';
  adsMaster.FieldByName('Deliver').AsString:='--';
  adsMaster.FieldByName('Apportion').AsString:='--';
  SpeedButton1.Enabled :=True;
  SpeedButton1.Enabled :=True;
end;

procedure TSTEdSLGoodsOutCostForm.Open(VoucherID: Integer);
begin
  inherited Open(VoucherID);
end;


procedure TSTEdSLGoodsOutCostForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
  inherited;
  adsMaster.Close;
  adsDetail.Close;
  ClientName.Close;
  EmployeeName.Close;
  GoodName.Close;
  PackUnit.Close;
  adsWarehouse.Close;
  adsGoodsSpec.Close;
end;

procedure TSTEdSLGoodsOutCostForm.FormCreate(Sender: TObject);
begin
  inherited;
  VoucherTableName := 'STSLGoodsOutCost';
  ClientName.Open;
  EmployeeName.Open;
  GoodName.Open;
  PackUnit.Open;
  adsWarehouse.Open;
  TempAds.Close;
  TempAds.CommandText :=' select Distinct brief from STSLGoodsOutCostMaster';
  TempAds.Open;
  TempAds.First;
  while not TempAds.Eof do
  begin
    BriefComboBox.Items.Add(TempAds.FieldByName('brief').AsString);
    TempAds.Next;
  end;
  if  TempAds.IsEmpty then  BriefComboBox.Items.Add('销售成本核算');
end;


procedure TSTEdSLGoodsOutCostForm.FormActivate(Sender: TObject);
begin
  inherited;
  ClientQLDBLookup.SetFocus;
end;


procedure TSTEdSLGoodsOutCostForm.BitBtn1Click(Sender: TObject);
begin
  TpcPanel.Visible :=true;
  TpcPanel.Repaint;
  BitBtn1.Enabled :=False;
  adsMaster.Edit;
  adsMaster.FieldByName('Apportion').AsString :=BitBtn1.Caption;
  TempQry.Close;
  TempQry.SQL.Text :=' select GoodsID,GoalUnitID, '
    +' sum(isnull(GoalQuantity,0)) as GoalQuantity ,'
    +' sum(isnull(Amount,0)) as Amount '
    +' from  ( '
    +' select a.GoodsID,c.unitID as GoalUnitID, '
    +' isnull(GoalQuantity,0)*Isnull(b.ModeDC,1)*Isnull(b.ModeC,1) as GoalQuantity ,'
    +' isnull(Amount,0)*Isnull(b.ModeDC,1)*Isnull(b.ModeC,1) as Amount '
    +' from  PCGoodsInDetail a '
    +' left outer join PCGoodsInMaster b on b.ID=a.MasterID'
    +' left outer join DAGoods c on c.ID=a.GoodsID  '
    +' where b.Date<=' +Quotedstr(datetostr(adsMaster.fieldbyname('ClearDate').asdatetime))
    +' and b.RecordState<>'+Quotedstr('删除')+' and b.RecordState<>'+Quotedstr('作废')
    +' and a.MasterID not in ( Select OriginID from STSLGoodsOutCostDetail )  '
    +' and Isnull(a.GoodsID,0)<>0 '
    +'  Union all  '
    +' select a.GoodsID,c.unitID as GoalUnitID, '
    +' isnull(GoalQuantity,0)*Isnull(b.ModeDC,1)*Isnull(b.ModeC,1) as GoalQuantity ,'
    +' isnull(Amount,0)*Isnull(b.ModeDC,1)*Isnull(b.ModeC,1) as Amount '
    +' from  YDGoodsInDetail a '
    +' left outer join YDGoodsInMaster b on b.ID=a.MasterID'
    +' left outer join DAGoods c on c.ID=a.GoodsID  '
    +' where b.Date<=' +Quotedstr(datetostr(adsMaster.fieldbyname('ClearDate').asdatetime))
    +' and b.RecordState<>'+Quotedstr('删除')+' and b.RecordState<>'+Quotedstr('作废')
    +' and a.MasterID not in ( Select OriginID from STSLGoodsOutCostDetail )  '
    +' and Isnull(a.GoodsID,0)<>0 '
    +' ) as a group by a.GoodsID,a.GoalUnitID '   ;
  TempQry.Open;
  DetailDataSource.DataSet :=nil;
  adsDetail.First;
  while not adsDetail.Eof do
  begin
    adsDetail.Edit ;
    TempQry.Locate('GoodsID',adsDetail.fieldbyname('GoodsID').AsInteger,[]);
    if (TempQry.fieldbyname('GoalQuantity').AsFloat<>0) then
       adsDetail.FieldByName('PriceGoal').AsFloat :=
         TempQry.fieldbyname('Amount').AsFloat/TempQry.fieldbyname('GoalQuantity').AsFloat;
    adsDetail.Next;
  end;
  DetailDataSource.DataSet :=adsDetail;
  BitBtn1.Enabled :=True;
  TpcPanel.Visible :=False;
end;

procedure TSTEdSLGoodsOutCostForm.BitBtn3Click(Sender: TObject);
begin
  adsMaster.Edit;
  adsMaster.FieldByName('Apportion').AsString :=BitBtn3.Caption;
end;

procedure TSTEdSLGoodsOutCostForm.BitBtn2Click(Sender: TObject);
begin
  adsMaster.Edit;
  adsMaster.FieldByName('Apportion').AsString :=BitBtn2.Caption;
end;

procedure TSTEdSLGoodsOutCostForm.BitBtn4Click(Sender: TObject);

⌨️ 快捷键说明

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