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

📄 bas_opbalance_d.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
                 'InvblncAmount=InvblncAmount'+'-('+oldInvAmount+'),'+
                 'InvblncPrice=case when isnull((Invblncqty'+'-('+oldInvQty+')),0)=0 then 0 else (InvblncAmount'+'-('+oldInvAmount+'))/(Invblncqty'+'-('+oldInvQty+')) end '+
              ' where InvMonth='''+lastMonth+''''+
              '  and VendorCode='''+oldVendorCode+''''+
              '  and ItemCode='''+oldItemCode+''''+
              ' update opAveragePrice '+
              '   set '+
              '   opApqty=opApqty'+'-('+oldInvQty+'),'+
              '   opApAmount=opApAmount'+'-('+oldInvAmount+'),'+
              '   opAveragePrice=case when isnull((opApqty'+'-('+oldInvQty+')),0)=0 then 0 else (opApAmount'+'-('+oldInvAmount+'))/(opApqty'+'-('+oldInvQty+')) end '+
              ' where VendorCode='''+oldVendorCode+''''+
              '   and ItemCode='''+oldItemCode+''' '+sqltext
         else
          sql.Text :=sql.Text+sqltext;
      //更新新的物料的Balance
      ExecSQL;
    end
  end;
  with AdoQry_Maintain do
  begin
    fieldbyname('InvMonth').asstring:=medt_InvMonth.Text;
    fieldbyname('VendorCode').asstring :=Extedt_Vendor.Text;
    fieldbyname('VendorName').asstring:=lbl_Vendor.Caption;
    fieldbyname('ItemCode').asstring:=Extedt_ItemCode.text;
    fieldbyname('ItemName').asstring:=lbl_ItemName.Caption;
    fieldbyname('UomName').asstring:=lbl_UomName.Caption;
    fieldbyname('InvQty').asstring:=Extedt_InvQty.text;
    fieldbyname('InvAmount').asstring:=Extedt_InvAmount.text;
    post;
  end;

end;


procedure TFrm_Bas_OpBalance_D.Extedt_InvQtyExit(Sender: TObject);
begin
  inherited;
  floatcheck(sender);

{  if strtofloat(Extedt_InvQty.text)<0 then
  begin
    DispInfo('结存数量不能小于零!',1);
    twincontrol(sender).setfocus;
    abort;
  end; }
  if (Extedt_InvAmount.text<>'') then
  begin
    if (Extedt_InvQty.text<>'0') then
      lbl_Price.Caption:=floattostr(strtofloat(Extedt_InvAmount.text)/strtofloat(Extedt_InvQty.text))
    else
      lbl_Price.Caption:='0';
  end; 
end;

procedure TFrm_Bas_OpBalance_D.Extedt_InvAmountExit(Sender: TObject);
var
  M:integer;
begin
  inherited;
  floatcheck(sender);

  if (strtofloat(Extedt_InvQty.text)<0) and (strtofloat(Extedt_InvAmount.text)>0)
      and (activecontrol.TabOrder>(sender as twincontrol).tabOrder)
      and (activecontrol.Name<>'btn_Cancel')  then
  begin
    DispInfo('结存数量不能小于零!',1);
    twincontrol(sender).setfocus;
    abort;
  end;
  if (strtofloat(Extedt_InvQty.text)>0) and (strtofloat(Extedt_InvAmount.text)<0)
     and (activecontrol.TabOrder>(sender as twincontrol).tabOrder)
     and (activecontrol.Name<>'btn_Cancel')  then
  begin
    DispInfo('结存金额不能小于零!',1);
    twincontrol(sender).setfocus;
    abort;
  end;
  if pos('.',Trim(Extedt_InvAmount.text))>0 then
  begin
    M:=length(Trim(Extedt_InvAmount.text))-pos('.',Trim(Extedt_InvAmount.text));
    if M>2 then
    begin
      DispInfo('只能录入两位小数!',1);
      twincontrol(sender).setfocus;
      abort;
    end;
  end;

  if (Extedt_InvQty.Text='0') or (Extedt_InvQty.Text='') then
     lbl_Price.Caption:='0'
  else
     lbl_Price.Caption:=floattostr(strtofloat(Extedt_InvAmount.text)/strtofloat(Extedt_InvQty.text))
end;

procedure TFrm_Bas_OpBalance_D.FormCreate(Sender: TObject);
begin
  inherited;
  SetFocus_Control:=medt_InvMonth;
end;
procedure TFrm_Bas_OpBalance_D.InOutItemCodeCheck(Sender: TObject);
begin
  inherited;
  if (Add) or
     ((not (Add)) and (Extedt_ItemCode.text<>AdoQry_Maintain.fieldbyname('ItemCode').asstring)) then
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.text:=
      'select UomName from Item,Uom where Item.ItemCode='''+Extedt_ItemCode.text+''' and Item.UomCode=Uom.UomCode ';
    open;
    lbl_UomName.Caption:=fieldbyname('UomName').asstring;
  end;
end;
procedure TFrm_Bas_OpBalance_D.btn_okClick(Sender: TObject);
var Currentperiod:string;
begin
  if ((strtofloat(Extedt_InvQty.Text)<0) and (strtofloat(Extedt_InvAmount.text)>0))
      or ((strtofloat(Extedt_InvQty.Text)>0) and (strtofloat(Extedt_InvAmount.text)<0)) then
      begin
        DispInfo('数量与金额在正负上必须统一!',3);
        abort;
      end;
  if (Add) or
     ((not (Add)) and ((Extedt_ItemCode.text<>oldItemCode) or (Extedt_Vendor.text<>oldVendorCode))) then
  begin
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.text:=
        ' select left(convert(varchAr,Invstatus),7) as InvStatus '+
        '  from Invstatus '+
        ' where InvStatusName=''clsperiod'' ';
      open;
      if not eof then
      begin
        if Trim(fieldbyname('Invstatus').asstring)>=medt_InvMonth.Text then
        begin
           showmessage(medt_InvMonth.text+'已经结帐,不允许进行期初维护');
           btn_Cancel.SetFocus ;
           abort;
        end;
        Currentperiod:=copy(datetostr(incMonth(strtodatetime(Trim(fieldbyname('Invstatus').asstring)+'.01'),1)),1,7);
        if Currentperiod<>medt_InvMonth.text then
        begin
           showmessage('月份应该是:'+Currentperiod);
           btn_Cancel.SetFocus ;
           abort;
        end;
      end;
    end;

    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.text:=' select ItemCode '+
                '   from OpBalance '+
                ' where VendorCode='''+getCode(Extedt_Vendor.Text)+''''+
                '   and ItemCode='''+Extedt_ItemCode.text+'''';
      open;
      if not eof then
      begin
        DispInfo('已经存在相同的记录,不允许增加或修改!',1);
        twincontrol(sender).setfocus;
        abort;
      end;
      Close;
      sql.clear;
      sql.text:=
        'select UomName from Item,Uom where Item.ItemCode='''+Extedt_ItemCode.text+''' and Item.UomCode=Uom.UomCode ';
      open;
      lbl_UomName.Caption:=fieldbyname('UomName').asstring;
    end;
  end;
    with AdoQry_tmp do
    begin
      Close;
      sql.Text :='select Count(*) cc from InvOutBill i1 join InvOutBillline i2 on i1.InvBillid=i2.InvBillid where i1.VendorCode='''+Extedt_Vendor.text+''' and i2.ItemCode='''+Extedt_ItemCode.text+'''';
      open;
      if fieldbyname('cc').asinteger>0 then
      begin
        DispInfo('已发生出入库,不允许进行期初维护',3);
        btn_Cancel.SetFocus ;
        abort;
      end;
   end;
  inherited;

end;

procedure TFrm_Bas_OpBalance_D.MonthCheck(Sender: TObject);
var
  onlyQuery:boolean;
begin
 inherited;
  {
    onlyQuery:=False;
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.Add('select top 1 InvMonth from OpBalance ');
      open;
      if (fieldbyname('InvMonth').asstring<>'') and (fieldbyname('InvMonth').asstring<>medt_InvMonth.text) then
      begin
        DispInfo('已经录入了其它月份的数据!',1);
        medt_InvMonth.setfocus;
        abort;
      end;
    end;
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.Add('select Count(*) as record from InvOutBill ');
      open;
      if fieldbyname('record').asinteger>0 then
         onlyQuery:=True;
    end;
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.Add('select Count(*) as record from InvInBill where initdata=0');
      open;
      if fieldbyname('record').asinteger>0 then
         onlyQuery:=True;
    end;

    if onlyQuery=True then
    begin
      // DispInfo('该仓库已经有出入库数据发生,不允许进行期初余额维护,只能查询!',3);
       DispInfo('该仓库已经有出入库数据发生,只能查询!',3);
      // twincontrol(sender).setfocus;
       btn_Cancel.SetFocus ;
       abort;
    end;
    }
end;

end.

⌨️ 快捷键说明

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