posfrm.pas

来自「医药连锁经营管理系统源码」· PAS 代码 · 共 1,216 行 · 第 1/3 页

PAS
1,216
字号
    dBornSum := dBornSum-BornSum;
    dTotal := dTotal-Amount;
    lbTotal.Caption := FormatFloat('0.00', dTotal);
    DispPriceTotal;
{	  if (not CkNoPrint.Checked) and LinePrintMode then begin //如果打小票
      xRunQuery(Qr_GoodsCalc, sqGoods+' WHERE ID='''+GoodsID+'''');
      if PrintWithRemark and (Qr_GoodsCalc.Fields[1].AsString<>'') then
        sGName := Qr_GoodsCalc.Fields[1].AsString
      else
        sGName := Qr_GoodsCalc.Fields[0].AsString;
      PrintGoods(GoodsID, sGName, GUnit, -Number, Price, -BornSum);
    end;
}  end;
{  SetLength(SaleGoodses, k+1);//这里千万不能要,否则会退重复药品
  SaleGoodses[k] := SaleInfo;}
//  AppendSaleGoods(SaleInfo);
end;

procedure TFmPOS.edInputKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var sInput: String;
		i, k: Integer;
    dRebate, d1: Double;
begin
	if Key=VK_NEXT then begin
  	lvSaleGoodses.SetFocus;
    Exit;
  end else if Key=VK_UP then begin
    Key := 0;
  	if lvSaleGoodses.Selected=nil then
    	i := lvSaleGoodses.Items.Count-1
    else
	  	i := lvSaleGoodses.Selected.Index;
  	if i>0 then
      lvSaleGoodses.Selected := lvSaleGoodses.Items[i-1];
  end else if Key=VK_DOWN then begin
    Key := 0;
    k := lvSaleGoodses.Items.Count;
  	if lvSaleGoodses.Selected=nil then
    	i := 0
    else
	  	i := lvSaleGoodses.Selected.Index;
  	if i<k-1 then
      lvSaleGoodses.Selected := lvSaleGoodses.Items[i+1];
  end;
  sInput := edInput.Text;
 	if sInput='' then Exit;
  if Key=VK_F5 then begin
  	dRebate := StrToFloat(sInput);
{    if dRebate<MinRebate then begin
      SetOptHint('折扣率超出指定范围,操作无效!');
      Exit;
    end;
}    edInput.Text := '';
    k := lvSaleGoodses.Items.Count;
    if lvSaleGoodses.Selected=nil then
    	i := k-1
    else
	  	i := lvSaleGoodses.Selected.Index;
  	if i<k-1 then begin
      with Qr_Temp do begin
        Close;
        SQL.Text := Format('SELECT Special FROM GOODSES WHERE ID=''%s''', [SaleGoodses[i].GoodsID]);
        Open;
      end;
      if Qr_Temp.Fields[0].AsBoolean then begin
      	SetOptHint('特价商品不能打折!');
        Exit;
      end else begin
        d1 := SaleGoodses[i].Amount;
        SaleGoodses[i].Rebate := dRebate;
        SaleGoodses[i].Amount := xRound(SaleGoodses[i].BornSum*dRebate/100);
        lvSaleGoodses.Items[i].SubItems[6] := FormatFloat('#,##0.00', SaleGoodses[i].Amount);
        dTotal := dTotal+SaleGoodses[i].Amount-d1;
        lbTotal.Caption := FormatFloat('0.00', dTotal);
        DispPriceTotal;
      end;
    end else
	    SaleGoods.Rebate := dRebate;
    lvSaleGoodses.Items[i].SubItems[5] := sInput;
  end else if Key=VK_F7 then begin
  	dRebate := StrToFloat(sInput);
{    if dRebate<MinRebate then begin
      SetOptHint('折扣率超出指定范围,操作无效!');
      Exit;
    end;
}    dWholeRebate := dRebate;
  	SaleGoods.Rebate := dWholeRebate;
    WholeRebate;
    edInput.Text := '';
  end else if Key=13 then begin
  	SaleGoods.GoodsID := sInput;
		edInput.Text := '';
    if ParseSaleInfo(SaleGoods) then begin
	    AppendSaleGoods(SaleGoods);
    end else begin
			edInput.Text := sInput;
      edInput.SelStart := Length(sInput);
    	Exit;
    end;
  end else if Key=VK_F11 then begin
  	if SaveBill then begin
  	  edInput.Text := '';
    end;
  end else if key=VK_F12 then begin
    with Qr_Temp do begin
      Close;
      SQL.Text :=  'SELECT 1 FROM EMPLOYEES WHERE EMPID='''+sInput+''' ';
      Open;
    end;
    if not Qr_Temp.IsEmpty then begin
      edEmpID.Text := sInput;
  	  edInput.Text := '';
    end else
      SetOptHint('请指定正确的员工编号!');
  end;
end;

procedure TFmPOS.edInputKeyPress(Sender: TObject; var Key: Char);
var	dNum: Double;
		sInput: String;
begin
  sInput := edInput.Text;
	if Key='*' then begin//当用户按下"*"键
    Key := CHR(0);
    if sInput='' then Exit;
  	dNum := StrToFloat(sInput);
    if dNum<>0 then
	    SaleGoods.Number := dNum;
    lvSaleGoodses.Items[lvSaleGoodses.Items.Count-1].SubItems[3] := sInput;
    edInput.Text := '';
  end else if Key='/' then begin
    Key := CHR(0);
{    if not HasPopedom(27) then begin//不能处理退货
      SetOptHint('对不起,你没有变价销售的权限!');
      Exit;
    end;
}    if sInput='' then Exit;
    SaleGoods.Price := StrToFloat(sInput);
    lvSaleGoodses.Items[lvSaleGoodses.Items.Count-1].SubItems[4] := sInput;
	  edInput.Text := '';
  end else if Key='+' then begin
    Key := CHR(0);
  	if SaveBill then begin
	    edInput.Text := '';
    end;
  end;
end;

function TFmPOS.AddEmptyLine: TListItem;
var n, k: Integer;
begin
  Result := lvSaleGoodses.Items.Add;
  k := lvSaleGoodses.Columns.Count-2;
  for n:=0 to k do
  	Result.SubItems.Add('');
  SaleGoods.Number := 1;
  SaleGoods.Price	 :=-1;//尚未指定单价
  SaleGoods.Rebate := dWholeRebate;
{  if AutoAddEmptyLine then
    lvSaleGoodses.Selected := Result;}
end;

Procedure TFmPOS.AppendSaleGoods(SaleInfo: TSaleGoodsInfo);
const sqGoods = 'SELECT NAME, SPECS, UNIT, UNIT2, CONV, CANSPLIT, PDCADDR, MAKER, Special, Remark FROM GOODSES ';
var k: Integer;
		str, sID, sGName, sSpecs, sRemark: String;
    ListItem: TListItem;
    pt: TPoint;
begin
	sID := SaleInfo.GoodsID;
  with Qr_GoodsCalc do begin
    Close;
    SQL.Text := sqGoods+' WHERE ID='''+sID+'''';
    Open;
  end;
  k := Length(SaleGoodses);
  SetLength(SaleGoodses, k+1);
  SaleGoodses[k] := SaleInfo;
  sGName := Qr_GoodsCalc.Fields[0].AsString;
  sSpecs := Qr_GoodsCalc.Fields[1].AsString;
  sRemark:= Qr_GoodsCalc.Fields[9].AsString;
  ListItem := lvSaleGoodses.Items[lvSaleGoodses.Items.Count-1];
  lvSaleGoodses.Selected := ListItem;
  AddEmptyLine;
  with SaleGoodses[k] do begin
	  ListItem.Caption := GoodsID;
    ListItem.SubItems[0] := sGName;
    ListItem.SubItems[1] := sSpecs;
    ListItem.SubItems[2] := GUnit;
    ListItem.SubItems[3] := FloattoStr(Number);
    ListItem.SubItems[4] := FormatFloat('0.00#', Price);
    if Rebate<>0 then
	    ListItem.SubItems[5] := FloattoStr(Rebate)
    else
	    ListItem.SubItems[5] := '';
    ListItem.SubItems[6] := FormatFloat('#,##0.00', Amount);

    dPrice := Price;
    dBornSum := dBornSum+BornSum;
    dTotal := dTotal+Amount;
    lbTotal.Caption := FormatFloat('0.00', dTotal);
    lbGoodsName.Caption := sGName;
    lbGoodsSpecs.Caption:= sSpecs;
    lbUnit.Caption			:= Qr_GoodsCalc.Fields[2].AsString;
    lbUnit2.Caption			:= Qr_GoodsCalc.Fields[3].AsString;
    lbConv.Caption			:= Qr_GoodsCalc.Fields[4].AsString;
    if Qr_GoodsCalc.Fields[5].AsBoolean then
    	lbSplit.Caption := '允许拆零:√'
    else
    	lbSplit.Caption := '允许拆零:';
    lbGoodsMaker.Caption:= Qr_GoodsCalc.Fields[6].AsString+Qr_GoodsCalc.Fields[7].AsString;
    if Qr_GoodsCalc.Fields[8].AsBoolean then
    	lbSpecial.Caption := '特价商品:√'
    else
    	lbSpecial.Caption := '特价商品:';
    if k=0 then begin
        lbPayMoney.Caption  := '';
        lbChange.Caption		:= '';
    end;
{	  if (not CkNoPrint.Checked)and LinePrintMode then begin //如果打小票
      if k=0 then begin
				Timer2.Enabled := false;
    	  PrintHeader(edBranchID.Text, edMachNo.Text, 'No.'+Qr_RetailBillNo.AsString, xCurrUser);
      end;
      if PrintWithRemark and (sRemark<>'') then
        sGName := sRemark;
  	  PrintGoods(sID, sGName, GUnit, Number, Price, BornSum);
    end;
}    DispPriceTotal;
	end;
  pt := lvSaleGoodses.Items[lvSaleGoodses.Items.Count-1].GetPosition;
  lvSaleGoodses.Scroll(pt.x, pt.y);

{  if Qr_PromotLargess.Active and not LargessWriting then begin
    LargessWriting := true;
    try//写赠品记录
      with Qr_PromotLargess do begin
        First;
        while not Eof do begin
          SaleInfo.GoodsID := Fields[0].AsString;
          saleInfo.Number  := Fields[1].AsFloat;
          SaleInfo.GUnit   := Fields[2].AsString;
          SaleInfo.Price   := 0;
          SaleInfo.Amount  := 0;
          SaleInfo.BornSum := 0;
          Next;
          str := 'SELECT 1 FROM GiftManage where GoodsID=''%s'' AND Unit=''%s'' AND STOP=1';
          str := Format(str, [SaleInfo.GoodsID,SaleInfo.GUnit]);
          xRunQuery(TmpQuery, str);
          if TmpQuery.IsEmpty then
            AppendSaleGoods(SaleInfo);
        end;
      end;
    finally
      LargessWriting := false;
      Qr_PromotLargess.Close;
    end;
  end;}
end;

procedure TFmPOS.HeaderCtrlSectionResize(HeaderControl: THeaderControl;
  Section: THeaderSection);
var n, k: Integer;
begin
	n := Section.Index;
  k := Section.Width;
  if n=0 then Dec(k);
	lvSaleGoodses.Columns[n].Width := k;
end;

procedure TFmPOS.plInputBkResize(Sender: TObject);
begin
	lbOptHint.Width := plInputBk.Width-plInput.Width-lbOptHint.Left*2;
end;

procedure TFmPOS.NewBill;
begin
  edCustNo.Text := '';
  EdEmpID.Text := '';
  dTotal := 0;
	dBornSum := 0;
  dWholeRebate := 100;
  SetLength(SaleGoodses, 0);
  lvSaleGoodses.Items.Clear;
{  Qr_Retail.Append;
  AddEmptyLine;}
end;

function TFmPOS.SaveBill: Boolean;
const
	sqIns = 'INSERT INTO RETAILLIST(BRANCHID, MACHNO, BILLNO, GOODSID, UNIT, [NUMBER], PRICE, REBATE, AMOUNT) '
				 +'VALUES(:V0, :V1, :V2, :V3, :V4, :V5, :V6, :V7, :V8) ';
  sqUpd1 = 'UPDATE RETAILLIST SET PriceModified=1 WHERE MachNo=%s AND BillNo=''%s'' AND (REBATE<>100 '
    +'OR EXISTS(SELECT 1 FROM GOODSES G WHERE G.ID=GOODSID AND Price<>G.%s AND RETAILLIST.Unit = G.Unit) '
    +'OR EXISTS(SELECT 1 FROM GOODSES G WHERE G.ID=GOODSID AND Price<>G.%s AND RETAILLIST.Unit = G.Unit2))';
  sqUpd2 = 'UPDATE RETAILLIST SET PriceModified=1 WHERE MachNo=%s AND BillNo=''%s'' AND (REBATE<>100 '
    +'OR EXISTS(SELECT 1 FROM GOODSES G, GoodsPrice P WHERE G.ID=RETAILLIST.GOODSID AND P.GoodsID=G.ID AND Price<>P.%s AND RETAILLIST.Unit = G.Unit) '
    +'OR EXISTS(SELECT 1 FROM GOODSES G, GoodsPrice P WHERE G.ID=RETAILLIST.GOODSID AND P.GoodsID=G.ID AND Price<>P.%s AND RETAILLIST.Unit = G.Unit2))';

	sqIns2= 'INSERT INTO UnNoteGoodsRetail(TeamNo, Operator, BRANCHID, MACHNO, BILLNO, GOODSID, UNIT, [NUMBER], PRICE, REBATE, AMOUNT, EmpID, Fdate) '
				 +'VALUES(%s, ''%s'', :V0, :V1, :V2, :V3, :V4, :V5, :V6, :V7, :V8, :V9, :V10) ';
var n, k: integer;
    UnNoteGoodsSum: Double;
		sBillNo, str1, str2, sPriceFld1, sPriceFld2: String;
begin
	Result := false;
  k := Length(SaleGoodses);
  if k=0 then Exit;
  if edInput.Text<>'' then begin
    dPayMoney := StrToFloat(edInput.Text);
  end else begin
{    if AutoTakePayMoney then
      dPayMoney := dTotal
    else   }
      Exit;
  end;
  dChange		:= dPayMoney-dTotal;
  dChange := Trunc(dChange*1000)/1000;//这样是为了避免出现相同数相减结果却不是0,而是一个极小数的错误。
  if dChange<0 then begin
{    if sDiscountGoods<>'' then begin//如果用户设置了折让药品代码
      if Application.MessageBox('客户付款不足,是否自动折让?', '折让', MB_YESNO+MB_ICONQUESTION+MB_DEFBUTTON2)=IDNO then
        Exit;
      AddEmptyLine;
      SaleGoods.GoodsID := sDiscountGoods;
      SaleGoods.Number  := 1;
      SaleGoods.Price   := -1;
      SaleGoods.Rebate  := 100;
      if ParseSaleInfo(SaleGoods) then begin
        if SaleGoods.Price>=0 then begin
          Application.MessageBox('用户对自动折让的药品设置为误,单价应小于0!', '错误', MB_OK+MB_ICONWARNING);
          Exit;
        end;
        SaleGoods.Number  := dChange/SaleGoods.Price;
        SaleGoods.BornSum := dChange;
        SaleGoods.Amount  := dChange;
        AppendSaleGoods(SaleGoods);
        dChange := 0;
      end;
    end else} begin
    	SetOptHint('客户支付金额不足,请重新输入!');
      Exit;
    end;
{  end else if dChange>=MaxChange then begin
   	SetOptHint('系统已设定最大找零金额不超过:'+FloatToStr(MaxChange));
    Exit;}
  end;
  lbPayMoney.Caption := FormatFloat('0.00', dPayMoney);
  lbChange.Caption	 := FormatFloat('0.00', dChange);

  UnNoteGoodsSum := 0;
  sBillNo := Qr_RetailBillNo.AsString;
  AdoConn.BeginTrans;
	try
//  	Qr_Retail.UpdateBatch;
    with Qr_Temp do begin
	    for n:=0 to Length(SaleGoodses)-1 do begin
        Close;
//        if sUnNoteGoods.IndexOf(SaleGoodses[n].GoodsID)<0 then begin
          SQL.Text := sqIns;
{        end else begin //不入帐药品
          str1 := Format(sqIns2, [edTeamNo.Text, xCurrUser]);
          SQL.Text := str1;
          Parameters[9].Value := edEmpID.Text;
          Parameters[10].Value := Now;
          UnNoteGoodsSum := UnNoteGoodsSum+SaleGoodses[n].Amount;
        end;}
        Parameters[0].Value := edBranchID.Text;
        Parameters[1].Value	:= edMachNo.Text;
        Parameters[2].Value := sBillNo;
  	    Parameters[3].Value := SaleGoodses[n].GoodsID;
        Parameters[4].Value := SaleGoodses[n].GUnit;
        Parameters[5].Value := SaleGoodses[n].Number;
        Parameters[6].Value := SaleGoodses[n].Price;
        if SaleGoodses[n].Rebate<>0 then
	        Parameters[7].Value := SaleGoodses[n].Rebate
        else
          Parameters[7].Value := NULL;
        Parameters[8].Value := SaleGoodses[n].Amount;
        ExecSQL;
       end;

      k := Qr_PosInfo.FieldByName('PriceModus').AsInteger;
      if k=0 then k:=4;
      case k of
        1: begin sPriceFld1 := 'PchPrice1'; sPriceFld2 :='PchPrice2'; end;
        2: begin sPriceFld1 := 'BatPrice1'; sPriceFld2 :='BatPrice2'; end;
        3: begin sPriceFld1 := 'StdPrice1'; sPriceFld2 :='StdPrice2'; end;
        4: begin sPriceFld1 := 'OdrPrice1'; sPriceFld2 :='OdrPrice2'; end;
        5: begin sPriceFld1 := 'OdrPrice3'; sPriceFld2 :='OdrPrice4'; end;
        6: begin sPriceFld1 :='OdrMPrice3'; sPriceFld2 :='OdrHPrice3'; end;
        7: begin sPriceFld1 :='OdrMPrice4'; sPriceFld2 :='OdrHPrice4'; end;
        else
          Raise Exception.Create('目前所设置的售价方案非法,以致于程序无法正常工作!请设置正确的售价方案!');
      end;
      if k<6 then
        str1 := Format(sqUpd1, [edMachNo.Text, sBillNo, sPriceFld1, sPriceFld2])
      else
        str1 := Format(sqUpd2, [edMachNo.Text, sBillNo, sPriceFld1, sPriceFld2]);
      SQL.Text := str1;
      ExecSQL;
    end;
  	Qr_RetailCustNo.AsString  := edCustNo.Text;
    Qr_RetailBornSum.AsFloat	:= dBornSum-UnNoteGoodsSum;
    Qr_RetailAmount.AsFloat		:= dTotal-UnNoteGoodsSum;
    Qr_RetailPayMoney.AsFloat := dPayMoney;

⌨️ 快捷键说明

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