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

📄 fmtscheckstocku.pas

📁 小型库存管理,希望有帮助,小型库存管理,希望有帮助
💻 PAS
字号:
unit FMTsCheckstockU;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FMBizMulU, DB, Menus, ADODB, Grids, DBGrids, dxDBGrid, dxDBTLCl,
  dxGrClms, dxTL, dxDBCtrl, dxCntner, ComCtrls, DBCtrls, StdCtrls, Mask,
  Buttons, ExtCtrls, ToolEdit, RXDBCtrl;

type
  TFMTsCheckstock = class(TFMBizMul)
    cdsDetailfBuyPrice: TFloatField;
    cdsDetailfStock: TIntegerField;
    GridDetailfStock: TdxDBGridColumn;
    procedure btnQueryClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnPrintClick(Sender: TObject);
    procedure cdsDetailfProductIdChange(Sender: TField);
    procedure btnCheckClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FMTsCheckstock: TFMTsCheckstock;

implementation

{$R *.dfm}
uses RepTsLostU ;


procedure TFMTsCheckstock.btnQueryClick(Sender: TObject);
begin
  PTableName :='ts_checkstock_head';
  inherited;
end;

procedure TFMTsCheckstock.FormCreate(Sender: TObject);
begin
  inherited;
  aPriceType := 1 ;
  aNumType :=0 ;
  aMainTable :='ts_checkstock_head';
  aDetailTable :='ts_checkstock_detail';
  aKeyField :='fBillId';
  aBillNo :='fBillNo';
  Style :='PD';
end;

procedure TFMTsCheckstock.btnPrintClick(Sender: TObject);
begin
  inherited;
  if Application.FindComponent('RepTsLost')=nil then
        RepTsLost:=TRepTsLost.create(self);
  RepTsLost.Caption :=Self.Caption ;
  RepTsLost.idtCompany.Caption :=aCompany ;
  RepTsLost.idtTitle.Caption :=Self.Caption;
  RepTsLost.cdsRep.Active :=false ;
  RepTsLost.cdsRep.CommandText :='SELECT a.*, b.fProductId, b.fqty, c.fProductNo, c.fProductName, c.fSpec, c.fSaleUnit, b.fBuyPrice,u.fusername '
   +' FROM ts_checkstock_head AS a, ts_checkstock_detail AS b, ts_item AS c,  ts_User AS u '
   +' WHERE a.fBillId=b.fBillId And b.fProductId=c.fProductId  '
   +' and a.fcreuser=u.fuserno and a.fBillId in '+GetPrintList
   +' order by a.fbillid,b.fProductId ' ;
  RepTsLost.cdsRep.Active :=true ;
  RepTsLost.Show ;
  RepTsLost.Visible :=false ;
  RepTsLost.QRep.Preview ;
end;

procedure TFMTsCheckstock.cdsDetailfProductIdChange(Sender: TField);
begin
  inherited;
  //取该商品的当前库存
  if cdsDetail.FieldByName('fProductName').AsString='' then exit ;

  QrySQL.Active :=false ;
  QrySQL.SQL.Text :='select fQty from tb_stock where  fProductid='+cdsDetail.FieldByName('fProductId').AsString;
  QrySQL.Open ;
  if QrySQL.Eof then
     cdsDetail.FieldByName('fStock').AsString :='0'
  else
     cdsDetail.FieldByName('fStock').AsString :=QrySQL.Fields[0].AsString ;

end;

procedure TFMTsCheckstock.btnCheckClick(Sender: TObject);
var
  strBillId,strBillNo,strAccDate,strMemo :string ;
begin
  inherited;
  if not cdsMain.Active then exit ;
  if cdsMain.FieldByName('fState').AsInteger <>3 then exit ;

  strAccDate :=cdsMain.fieldByname('fAccDate').AsString ;
  MessageBox(handle,'准备产生调整单.','提示',MB_OK+MB_ICONINFORMATION);

  strBillId :=GetNextId('ts_lost_head','fbillid');

  QrySQL.Active :=false ;
  QrySQL.SQL.Text :='insert into ts_lost_detail(fBillId,fEntryId,fProductId,fQty,fBuyPrice,fFFU)'
   +' select '+strBillId+',fEntryId,fProductId,fQty-fStock,fBuyPrice,0 '
   +' from ts_checkstock_detail'
   +' where fbillid='+cdsMain.FieldByName('fbillid').AsString;
  QrySQL.ExecSQL ;

  aMainTable :='ts_lost_head';
  strBillNo :=GeneratID ;
  strMemo :='该单据由盘点单产生:'+cdsMain.FieldByName('fBillNo').AsString;
  
  QrySQL.Active :=false ;
  QrySQL.SQL.Text :='insert into ts_lost_head(fBillId,fBillNo,fAccDate,fCreUser,fState,fMemo,fFFU)'
   +' values('+strBillId+','+#39+strBillNo+#39+','+#39+strAccDate+#39+','+#39+aUserId+#39+',1,'+#39+strMemo+#39+',0)';
  QrySQL.ExecSQL ;

  QrySQL.Active :=false ;
  aMainTable :='ts_checkstock_head';

  cdsMain.Edit ;
  cdsMain.FieldByName('fState').AsString :='4';
  cdsMain.Post ;

  MessageBox(handle,'调整单产生完毕.','提示',MB_OK+MB_ICONINFORMATION);
end;

end.

⌨️ 快捷键说明

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