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

📄 inv_opoutsale_b.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    if not CheckAllSame then//正负号同号检测
    begin
      DispInfo('不允许正负号同时出现!',1);
      //AdoQry_Body.Connection.RollBackTrans;
      disableall(True);
      AdoQry_Body.EnableControls;
      abort;
    end;

    With  AdoQry_Tmp do
    begin
      Close;
      Sql.clear;
      Sql.Add('Select PriceType from Warehouse where  WHCode='''+GetCode(Cmbx_WhCodeName.Text)+'''');
      Open;
      PriceType:=AdoQry_Tmp.fieldbyname('PriceType').AsInteger;
    end;
    BeforeSaveError:=False;
    BillNo:=GetNo(AdoQry_Tmp.Connection,GetCode(Cmbx_WhCodeName.Text)+'C'+
                  FormatDateTime('yymm',StrToDate(Medt_Date.Text)),
            'InvBill');
    ChangeInvStatus(AdoQry_tmp,getCode(Cmbx_WhCodeName.text),copy(Medt_Date.text,1,7));
    With AdoQry_Tmp do
    begin
      Close;
      Sql.clear;
      //增加单据头记录
      If IsOverPlan then
      AdoQry_tmp.sql.Add('insert into InvOutBill'+
                          '(InvBillno,'+
                          'OverPlan,'+
                          'whCode,'+
                          'InvBilldate,'+
                          'InvBillMonth,'+
                          'BillTypeCode,'+
                          'EmployeeCode,'+
                          'WH_EmployeeCode,'+
                          'VendorCode,'+
                          'PoNo,'+
                          'WhPositionCode,'+
                          'InvBillremArk)'+
                  'Values('''+Billno+''','+
                         '1,'+
                         ''''+getCode(Cmbx_WhCodeName.text)+''','+
                         ''''+Trim(medt_Date.text)+''','+
                         ''''+copy(medt_Date.text,1,7)+''','+
                         ''''+BillTypeCode+''','+
                         ''''+userCode+''','+
                         ''''+userCode+''','+
                         ''''+GetCode(Lbl_VendorCodeName.Caption)+''','+
                         ''''+FPoNo+''','+
                         ''''+getCode(Cmbx_Position.text)+''','+
                         ''''+Edt_memo.text+''')')
      else
      AdoQry_tmp.sql.Add('insert into InvOutBill'+
                          '(InvBillno,'+
                          'whCode,'+
                          'InvBilldate,'+
                          'InvBillMonth,'+
                          'BillTypeCode,'+
                          'EmployeeCode,'+
                          'WH_EmployeeCode,'+
                          'VendorCode,'+
                          'PoNo,'+
                          'WhPositionCode,'+
                          'InvBillremArk)'+
                  'Values('''+Billno+''','+
                         ''''+getCode(Cmbx_WhCodeName.text)+''','+
                         ''''+Trim(medt_Date.text)+''','+
                         ''''+copy(medt_Date.text,1,7)+''','+
                         ''''+BillTypeCode+''','+
                         ''''+userCode+''','+
                         ''''+userCode+''','+
                         ''''+GetCode(Lbl_VendorCodeName.Caption)+''','+
                         ''''+FPoNo+''','+
                         ''''+getCode(Cmbx_Position.text)+''','+
                         ''''+Edt_memo.text+''')');

         AdoQry_tmp.execsql;
         AdoQry_tmp.Close;
         AdoQry_tmp.sql.clear;
         AdoQry_tmp.sql.Add(' select @@IDENTITY as Billid ');
         AdoQry_tmp.open;
         Billid:=AdoQry_tmp.fieldbyname('Billid').asstring;
    end;
    with AdoQry_Body do
    begin
      First;
      for X:=0 to recordCount-1 do
      begin
      ItemListId:=AdoQry_Body.fieldbyname('ItemListId').asinteger;
        If AdoQry_Body.fieldbyname('PoOutQty').AsFloat=0 then
        begin
          next;
          continue;
        end;
        //如果本仓库属于移动加权平均价计价仓
        Price:=0;
        if True then//NeedChangePrice then
        begin
          if PriceType=0 then
          begin
            //正常委外领料,按常规移动加权平均价的算法计算
              //更改移动价
              AdoQry_tmp.Close;
              AdoQry_tmp.sql.clear;
              AdoQry_Tmp.Sql.Add('UpDate AveragePrice'+
                                ' Set ApQty=ApQty-('+
                                           AdoQry_Body.fieldbyname('PoOutQty').AsString+'),'+
                                       'ApAmount=case Apqty when 0 then 0 else round(ApAmount/Apqty*(Apqty-('+fieldbyname('PoOutQty').AsString+')),2) end '+
                                  ' where whCode='''+getCode(Cmbx_WhCodeName.Text)+''' and '+
                                '       ItemCode='''+fieldbyname('ItemCode').AsString+'''');
              AdoQry_Tmp.ExecSQL;

              //获取当前价格
              AdoQry_tmp.Close;
              AdoQry_tmp.sql.clear;
              AdoQry_Tmp.Sql.Add('Select AveragePrice from AveragePrice'+
                                 ' where whCode='''+getCode(Cmbx_WhCodeName.Text)+''' and '+
                               '       ItemCode='''+fieldbyname('ItemCode').AsString+'''');
              AdoQry_Tmp.open;
              Price:=AdoQry_Tmp.fieldbyname('AveragePrice').asfloat;
          end
          else
          //如果本仓库属于计划价仓库
          begin
            AdoQry_tmp.Close;
            AdoQry_tmp.sql.clear;
            AdoQry_tmp.sql.text:=
               'select isnull((Select isnull(SPPrice,0) From StandardPrice where '+
                  'SPStArtMonth='''+copy(medt_Date.text,1,7)+''''+
                  ' and ItemCode='''+fieldbyname('ItemCode').AsString+'''),0) Price';
            AdoQry_tmp.Open;
            Price:=AdoQry_tmp.fieldbyname('Price').asfloat;
          end;
        end;

        //插入单据行
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.clear;
        AdoQry_tmp.sql.Add('insert InvOutBillline'+
                                  '(InvBillid,'+
                                  'BatchNo,'+
                                  'InvBilllineno,'+
                                  'ItemCode,'+
                                  'ite_ItemCode,'+
                                  'pono,'+
                                  'polineno,'+
                                  'InvBillNoTaxPrice,'+
                                  'InvBillNoTaxAmount,'+
                                  'InvBillqty,BillLineReMArk) '+
                            'Select '+Billid+','+
                                    ''''+fieldbyname('BatchNo').asstring+''','+
                                    inttostr(X+1)+','+
                                    ''''+fieldbyname('ItemCode').asstring+''','+
                                    ''''+fieldbyname('ite_ItemCode').asstring+''','+
                                    ''''+lbl_Pono.Caption+''','+
                                    ''''+fieldbyname('polineno').asstring+''','+
                                    floattostr(Price)+','+
                                    ' Round('+fieldbyname('POOutQty').asstring+
                                    '*'+floattostr(Price)+',2),'+
                                    fieldbyname('POOutQty').asstring+','+
                                    ' '''+fieldbyname('BillLineReMArk').asstring+'''');
        AdoQry_tmp.ExecSQL;

        //更新REALSalEPRICE数据
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:='Insert RealSalePrice'+
          '(InvBillId,InvBillLineNo,InvBillSalePrice,InvBillSaleAmount,'+
          'InvBillNoTaxSalePrice,InvBillNoTaxSaleAmount)'+
          'Values('
          +''''+Billid+''''
          +','+IntToStr(X+1)+''
          +','+fieldbyname('SP2Price').AsString+''
          +','+fieldbyname('taxAmount').AsString+''
          +','+fieldbyname('sp2NoTaxPrice').AsString+''
          +','+fieldbyname('NoTaxAmount').AsString+''
          +')';
        AdoQry_Tmp.ExecSQL;
        AdoQry_tmp.Close;


         //更新本厂当前库存
        if UpdateInv(AdoQry_Tmp,
                  getCode(Cmbx_WhCodeName.text),
                  getCode(Cmbx_Position.text),
                  AdoQry_Body.fieldbyname('ItemCode').asstring,
                  '(-('+AdoQry_Body.fieldbyname('POOutQty').asstring+'))',
                  NeedChangePrice,True)<>'' then
          abort;

         //更新批次库存
        if AdoQry_Body.fieldbyname('BatchNo').asstring<>'' then
        ChangeBatchInv(AdoQry_Tmp2,
                      AdoQry_Body.fieldbyname('BatchNo').asstring,
                      'c',formatdatetime('YYYY.MM.DD',date),
                      getCode(Cmbx_WhCodeName.text),
                      getCode(Cmbx_Position.text),
                      AdoQry_Body.fieldbyname('POOutQty').asFloat);

        //更新领料清单
        //如果是原来清单中没有的物料,则Insert
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.clear;
        AdoQry_Tmp.SQL.Add('select Count(*) s from opItemList '+
                             'where pono='''+fpono+''' '+
                             '  and polineno='''+fieldbyname('polineno').asstring+''' '+
                             '  and ItemCode='''+fieldbyname('ItemCode').asstring+'''');
        AdoQry_Tmp.open;
        IF (AdoQry_Tmp.fieldbyname('s').Asinteger<=0) then
        begin
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.clear;
          AdoQry_Tmp.SQL.Add('Insert OpItemList '+
                                    '(PoNo,'+
                                    'PoLineNo,'+
                                    'ItemCode,'+
                                    'POCtrlQty,'+
                                    'PORealQty,'+
                                    'POOutQty,'+
                                    'usestyle)'+
                              'Values('''+FPoNo+''','+
                                     ''''+fieldbyname('POlineNo').AsString+''','+
                                     ''''+fieldbyname('ItemCode').AsString+''','+
                                     ''''+fieldbyname('POCtrlQty').AsString+''','+
                                     ''''+fieldbyname('POOutQty').AsString+''','+
                                     ''''+fieldbyname('POOutQty').AsString+''','+
                                     '1)');
          AdoQry_Tmp.ExecSql;
          Scll(AdoQry_tmp,fieldbyname('ItemCode').asstring,'POScLL',fieldbyname('PONO').AsString,fieldbyname('POLINENO').asinteger);
        end
        Else
        begin
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.clear;
          AdoQry_Tmp.SQL.Add('Update OpItemList Set'+
                             '  PoRealQty=PoRealQty+'+fieldbyname('POOutQty').AsString+','+
                             '  BillLineRemArk='''+AdoQry_Body.fieldbyname('BillLineRemArk').asstring+''' '+
                             'Where ItemListId='+inttostr(ItemListId));
          AdoQry_Tmp.ExecSql;
          Scll(AdoQry_tmp,fieldbyname('ItemCode').asstring,'POScLL',fieldbyname('PONO').AsString,fieldbyname('POLINENO').asinteger);

        end;
        next;
      end;
    end;
    AdoQry_Tmp.Connection.CommitTrans;
    AdoQry_Body.EnableControls;
    dbgrideh.ReadOnly:=True;
    Edt_Memo.Enabled:=False;
    Medt_Date.Enabled:=False;
    Edt_BillNo.text:=BillNo;
    act_Save.Enabled:=False;
    act_auto.enabled:=False;
    act_insertline.enabled:=False;
    act_Deleteline.enabled:=False;
    disableall(False);
  except
    AdoQry_Tmp.Connection.RollBackTrans;
    AdoQry_Body.EnableControls;
    if not BeforeSaveError then
      DispInfo(' 单据保存失败,请稍后再试! ',1);
  end;
end;

procedure TFrm_Inv_OpOutSale_B.Cmbx_WhCodeNameChange(Sender: TObject);
var
  tmpfields:string;
begin
  inherited;
  InitCmbx_WhPosition(GetCode(Cmbx_WhCodeName.Text));
  Cmbx_Position.ItemIndex:=InitwhposIfSpec;
  refreshall;
end;

procedure TFrm_Inv_OpOutSale_B.Cmbx_WhCodeNameExit(Sender: TObject);
begin
  inherited;
  If Cmbx_WhCodeName.Text='' then
  begin
    DispInfo('请选择一个仓库!',1);
    Abort;
  end;
end;

procedure TFrm_Inv_OpOutSale_B.Cmbx_PositionExit(Sender: TObject);
begin
  inherited;
  If Cmbx_Position.Text='' then
  begin
    DispInfo('请选择一个货位',1);
    Cmbx_Position.SetFocus;
    abort;
  end;
end;

procedure TFrm_Inv_OpOutSale_B.Medt_DateExit(Sender: TObject);
begin
  inherited;
  if not WHClsPeriodCheck(AdoQry_Tmp,GetCode(Cmbx_WhCodeName.Text),Copy((Medt_Date.Text),1,7)) then
  begin
    Medt_Date.SetFocus;
    act_Save.Enabled :=False;
    abort;
  end
  else if CheckNotZero then
  begin
   act_Save.Enabled :=True;
  end;
end;

procedure TFrm_Inv_OpOutSale_B.FormCreate(Sender: TObject);
begin
  inherited;
  Frm_Entry_Detail:=TFrm_Inv_OpOutSale_D.Create(Self);
end;

procedure TFrm_Inv_OpOutSale_B.FormActivate(Sender: TObject);
begin
  inherited;
//  ToolButton7.Action:=act_Check;
    act_Save.Enabled:=True;
//  ToolButton4.left:=TlBtn_Print.left+ToolButton4.Width;
  //跟据超订单标志进行初始化
  If IsOverPlan then
  begin
    Caption:='委外加工超订单材料销售';
    Pnl_Title.Caption:='委外加工超订单材料销售';
    act_insertline.Visible:=True;
    act_Deleteline.Visible:=True;
    act_auto.Visible:=False;
  end
  Else
  begin
    Caption:='委外加工材料销售';
    Pnl_Title.Caption:='委外加工材料销售';
    act_insertline.Visible:=False;
    act_Deleteline.Visible:=False;
    act_auto.Visible:=True;
  end;
  if (Addormodify) and (isOverPlan) then
  begin
    act_insertline.Enabled:=True;
    act_Deleteline.Enabled:=True;
    act_Save.visible:=True;
    DBGridEh.ReadOnly:=True;
    DBGridEh.Columns[0].ReadOnly:=True;
    DBGridEh.Columns[1].ReadOnly:=True;
    DBGridEh.Columns[2].ReadOnly:=True;
    DBGridEh.Columns[3].ReadOnly:=True;
    DBGridEh.Columns[4].ReadOnly:=True;
    DBGridEh.Columns[5].ReadOnly:=True;
    DBGridEh.Columns[6].ReadOnly:=True;
    DBGridEh.Columns[7].ReadOnly:=True;
    DBGridEh.Columns[8].ReadOnly:=True;
    DBGridEh.Columns[9].ReadOnly:=True;
    DBGridEh.Columns[10].ReadOnly:=True;
    DBGridEh.Columns[11].ReadOnly:=True;
  end
  else if (isOverPlan) and (not Addormodify) then
  begin
    act_insertline.Enabled:=False;
    act_Deleteline.Enabled:=False;
    DBGridEh.ReadOnly:=True;
  end
  else if (not isOverPlan) and (Addormodify) then
  begin
    act_auto.Enabled:=True;
    DBGridEh.ReadOnly:=False;
    DBGridEh.Columns[0].ReadOnly:=True;
    DBGridEh.Columns[1].ReadOnly:=True;
    DBGridEh.Columns[2].ReadOnly:=True;
    DBGridEh.Columns[3].ReadOnly:=True;
    DBGridEh.Columns[4].ReadOnly:=True;
    DBGridEh.Columns[5].ReadOnly:=True;
    DBGridEh.Columns[6].ReadOnly:=True;
    DBGridEh.Columns[7].ReadOnly:=False;
    DBGridEh.Columns[8].ReadOnly:=False;
    DBGridEh.Columns[9].ReadOnly:=False;
    DBGridEh.Columns[10].ReadOnly:=True;
    DBGridEh.Columns[11].ReadOnly:=True;
    DBGridEh.Columns[12].ReadOnly:=True;
    DBGridEh.Columns[13].ReadOnly:=True;
    DBGridEh.Columns[14].ReadOnly:=True;
    DBGridEh.Columns[15].ReadOnly:=True;
    DBGridEh.Columns[16].ReadOnly:=True;
  end
  else if (not isOverPlan) and (not Addormodify) then
  begin
    DBGridEh.ReadOnly:=True;
    act_auto.Enabled:=False;
  end;
end;

procedure TFrm_Inv_OpOutSale_B.Act_SaveExecute(Sender: TObject);
begin
  //跟据超订单标志进行数据存盘
  if CheckNotZero then
  begin
    //inherited;
    If IsOverPlan then
    begin
      Caption:='委外加工超订单材料销售';
      Pnl_Title.Caption:='委外加工超订单材料销售';
    end
    Else
    begin
      Caption:='委外加工材料销售';
      Pnl_Title.Caption:='委外加工材料销售';
      Act_DeleteLine.Enabled:=False;
      Act_InsertLine.Enabled:=False;
    end;
  end
  else
  begin
    DispInfo('出库均为零,不能保存!',3);
    act_Save.Enabled:=False;
    exit;
  end;
  savedata;
end;

procedure TFrm_Inv_OpOutSale_B.Cmbx_PositionChange(Sender: TObject);
begin
  inherited;
  //act_Save.enabled:=True;

⌨️ 快捷键说明

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