//1_msg//lbl7 private void CloseCheque_single(bool isLegalMode) { uiWndPayment pMethod = new uiWndPayment(realSUMA); pMethod.ShowDialog(); pMethod.Dispose(); //winapi.Funcs.OutputDebugString("A"); if (pMethod.DialogResult != DialogResult.OK) return; object[] localData = new object[8]; string chqNom = string.Empty; switch (pMethod.Type[0]) { case 0: { digitalPanel.BackgroundImage = Properties.Resources.payment_card; break; } case 1: { digitalPanel.BackgroundImage = Properties.Resources.payment_credit; break; } case 2: { digitalPanel.BackgroundImage = Properties.Resources.payment_cheque; break; } case 3: { digitalPanel.BackgroundImage = Properties.Resources.payment_cash; break; } } if (UserConfig.Properties[4] && DialogResult.Yes == MMessageBoxEx.Show(this.chequeDGV, "Видати накладну згідно цього чеку ?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { _fl_taxDocRequired = true; CashLbl.Image = Properties.Resources.naklad; } localData[0] = clientID == string.Empty ? ConfigManager.Instance.CommonConfiguration.APP_ClientID : clientID; localData[1] = discCommonPercent; localData[2] = realSUMA; localData[3] = taxSUMA; localData[4] = _fl_taxDocRequired; localData[5] = _fl_isReturnCheque; localData[6] = _fl_useTotDisc; //winapi.Funcs.OutputDebugString("B"); if (isLegalMode) { try { if (_fl_isReturnCheque) Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_PayMoney", Cheque, ConfigManager.Instance.CommonConfiguration.APP_DoseDecimals, _fl_useTotDisc, ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals); else Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_Sale", Cheque, ConfigManager.Instance.CommonConfiguration.APP_DoseDecimals, _fl_useTotDisc, ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals); if (_fl_useTotDisc && discCommonPercent != 0.0) { //if ((discount[0] + discount[1]) != 0 || constDiscount != 0) //OnDeactivate(EventArgs.Empty); //double[] valueDISC = new double[] { // discount[0], // cash_discount[0], // discount[1], // cash_discount[1], // constDiscount}; //byte[] types = new byte[] { 2, 3, 2, 3, 2 }; //for (int i = 0; i < valueDISC.Length; i++) // if (valueDISC[i] != 0.0) ; Program.AppPlugins.GetActive<IFPDriver>().CallFunction( "FP_Discount", new object[] { (byte)2/*types[i]*/, /*valueDISC[i]*/discCommonPercent/*(discount[0] + discount[1]) == 0 ? constDiscount : (discount[0] + discount[1])*/, ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals, "" }); } if (lastPayment >= pMethod.Type.Count) lastPayment = 0; for (int i = lastPayment; i < pMethod.Type.Count; i++) { Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_Payment", pMethod.Type[i], pMethod.ItemsCash[i], pMethod.Autoclose); lastPayment++; } chqNom = Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_LastChqNo", _fl_isReturnCheque).ToString(); localData[7] = Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_LastZRepNo", _fl_isReturnCheque); } catch (Exception ex) { CoreLib.WriteLog(ex, System.Reflection.MethodInfo.GetCurrentMethod().Name); MMessageBoxEx.Show(this.chequeDGV, "Помилка під час закриття чеку" + "\r\n" + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); bool customOrderNo = false; uiWndChqNomRequest chqR = new uiWndChqNomRequest(); if (chqR.ShowDialog(this.chequeDGV) == System.Windows.Forms.DialogResult.Yes) { customOrderNo = true; chqNom = chqR.ChequeNumber.ToString(); } chqR.Dispose(); if (!customOrderNo) return; /* MMessageBox.Show(this, "Натисніть ОК та повторно закрийте чек." + "\r\n", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); */ //Program.AppPlugins.GetActive<IFPDriver>().CallFunction("ResetOrder"); //ChqNomRequest cnr = new ChqNomRequest(); //cnr.ShowDialog(); //cnr.Dispose(); //if (cnr.DialogResult != DialogResult.Yes) //chqNom = cnr.ChequeNumber.ToString(); } try { Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_OpenBox"); } catch (Exception ex) { MMessageBoxEx.Show(this.chequeDGV, "Помилка відкриття грошової скриньки" + "\r\n" + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); CoreLib.WriteLog(ex, System.Reflection.MethodInfo.GetCurrentMethod().Name); } } lastPayment = 0; //winapi.Funcs.OutputDebugString("C"); chqNom = DataWorkCheque.SaveCheque(Cheque, localData, pMethod.Type[0], chqNom); //object[] printerData = this.CreatePrinterData(fix, pMethod.PaymentInfo); //Dictionary<string, object> printerData = this.PD_Order; // add additional information //DataWorkShared.SetOrderProperty(this.PD_Order, CoreConst.ORDER_NO, chqNom); DataWorkShared.SetOrderProperty(this.Cheque, CoreConst.PAYMENT, pMethod.PaymentInfo); DataWorkShared.SetOrderProperty(this.Cheque, CoreConst.ORDER_NO, isLegalMode ? chqNom : 'N' + chqNom); // 1 this.PD_EmptyOrder.ExtendedProperties["ORDER_NO"] = chqNom; // 1 this.PD_EmptyOrder.ExtendedProperties["PAYMENT"] = pMethod.PaymentInfo; //printerData["IS_LEGAL"] = isLegalMode; //Printing //winapi.Funcs.OutputDebugString("D"); if (isLegalMode && UserConfig.Properties[10]) { DataWorkOutput.Print(Enums.PrinterType.OrderLegal, this.PD_Order); //CoreLib.Print(printerData, "fix", 0); } if (!isLegalMode && UserConfig.Properties[11]) { DataWorkOutput.Print(Enums.PrinterType.OrderNormal, this.PD_Order); //CoreLib.Print(printerData, "none", 0); } if (DataWorkShared.ExtractBillProperty(this.PD_Order, CoreConst.OID, string.Empty) != string.Empty) { //CoreLib.LockBill(this.PD_Order.Copy(), chqNom); if (ConfigManager.Instance.CommonConfiguration.Content_Bills_KeepAliveAfterCheque) DataWorkBill.LockBill(this.PD_Order.Copy(), isLegalMode ? chqNom : 'N' + chqNom); else DataWorkBill.BillDelete(this.PD_Order); //Cheque.ExtendedProperties["FXNO"] = chqNom; //File.Delete(Cheque.ExtendedProperties["PATH"].ToString()); } RowsRemoved_MyEvent(false, true, true); CashLbl.ForeColor = ConfigManager.Instance.CommonConfiguration.STYLE_RestFontColor; CashLbl.Font = ConfigManager.Instance.CommonConfiguration.STYLE_RestFont; CashLbl.Text = string.Format("{0:F" + ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals + "}", pMethod.Rest); chequeInfoLabel.Text = string.Format("{0} {1:F" + ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals + "}", "залишок з суми", pMethod.CashSum); addChequeInfo.Text = string.Format("{0} {1} ", "Закритий чек №", chqNom); if (DataWorkShared.ExtractBillProperty(this.PD_Order, CoreConst.BILL_NO, string.Empty) != string.Empty) addChequeInfo.Text += string.Format("{0} {1} ", "з рахунку №", DataWorkShared.ExtractBillProperty(this.PD_Order, CoreConst.BILL_NO, string.Empty)); this.addBillInfo.Text = string.Empty; if (isLegalMode && ConfigManager.Instance.CommonConfiguration.APP_ShowInfoOnIndicator) try { string[] lines = new string[2]; lines[0] = string.Format("{0} : {1:F" + ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals + "}", "Гроші", pMethod.CashSum); lines[1] = string.Format("{0} : {1}", "Здача", CashLbl.Text); bool[] show = new bool[] { true, true }; Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_SendCustomer", lines, show); } catch { } //winapi.Funcs.OutputDebugString("E"); }
//1_msg//lbl7 /// <summary> /// Закриття чеку /// </summary> /// <param name="isLegalMode">Якщо true то чек є фіскальний</param> private void CloseCheque_profile(bool isLegalMode) { List<Hashtable> fullResult = new List<Hashtable>(); Hashtable profileResult = new Hashtable(); bool appIsLegal = isLegalMode; int pIdx = 0; object currentProfileKey = new object(); object[] localData = new object[9]; string chqNom = string.Empty; List<string> chqNumbers = new List<string>(); List<string> chqNumbersFull = new List<string>(); bool generalError = false; uiWndPayment pMethod = new uiWndPayment(realSUMA, true); pMethod.ShowDialog(); pMethod.Dispose(); if (pMethod.DialogResult != DialogResult.OK) return; if (UserConfig.Properties[4] && DialogResult.Yes == MMessageBoxEx.Show(this.chequeDGV, "Видати накладну згідно цього чеку ?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { _fl_taxDocRequired = true; CashLbl.Image = Properties.Resources.naklad; } switch (pMethod.Type[0]) { case 0: { digitalPanel.BackgroundImage = Properties.Resources.payment_card; break; } case 1: { digitalPanel.BackgroundImage = Properties.Resources.payment_credit; break; } case 2: { digitalPanel.BackgroundImage = Properties.Resources.payment_cheque; break; } case 3: { digitalPanel.BackgroundImage = Properties.Resources.payment_cash; break; } } // check if there are any profile as legal marked // if it exists - use it at first and then all other // otherwise peroform profiles as they are List<string> _allProfiles = new List<string>(); bool hasLegalProfile = ConfigManager.Instance.CommonConfiguration.PROFILES_Items.ContainsKey(ConfigManager.Instance.CommonConfiguration.PROFILES_LegalProgileID); foreach (DictionaryEntry de in ConfigManager.Instance.CommonConfiguration.PROFILES_Items) _allProfiles.Add(de.Key.ToString()); if (hasLegalProfile) { _allProfiles.Remove(ConfigManager.Instance.CommonConfiguration.PROFILES_LegalProgileID.ToString()); _allProfiles.Insert(0, ConfigManager.Instance.CommonConfiguration.PROFILES_LegalProgileID.ToString()); } Dictionary<string, object> _orgPaymanet = pMethod.PaymentInfo; DataTable dtCopy = this.PD_Order.Copy(); int skippedProfiles = 0; //foreach (DictionaryEntry de in ConfigManager.Instance.CommonConfiguration.PROFILES_Items) foreach (string profileKey in _allProfiles.ToArray()) { try { // profile id //profileKey = de.Key; // profile main index currentProfileKey = profileKey; pIdx++; Hashtable _suma = (Hashtable)this.Summa[profileKey]; Hashtable _discount = (Hashtable)this.Discount[profileKey]; DataTable _cheque = this.Cheques.Tables[profileKey.ToString()]; if (_cheque.Rows.Count == 0) { skippedProfiles++; continue; } /* initializing discount values */ double[] _discArrPercent = CoreLib.GetValue<double[]>(_discount, CoreConst.DISC_ARRAY_PERCENT); double[] _discArrCash = CoreLib.GetValue<double[]>(_discount, CoreConst.DISC_ARRAY_CASH); double _discConstPercent = CoreLib.GetValue<double>(_discount, CoreConst.DISC_CONST_PERCENT); double _discOnlyPercent = CoreLib.GetValue<double>(_discount, CoreConst.DISC_ONLY_PERCENT); double _discOnlyCash = CoreLib.GetValue<double>(_discount, CoreConst.DISC_ONLY_CASH); double _discCommonPercent = CoreLib.GetValue<double>(_discount, CoreConst.DISC_FINAL_PERCENT); double _discCommonCash = CoreLib.GetValue<double>(_discount, CoreConst.DISC_FINAL_CASH); /* calculation items */ double _realSUMA = CoreLib.GetValue<double>(_suma, CoreConst.CALC_REAL_SUMA); double _chqSUMA = CoreLib.GetValue<double>(_suma, CoreConst.CALC_CHEQUE_SUMA); double _taxSUMA = CoreLib.GetValue<double>(_suma, CoreConst.CALC_TAX_SUMA); // it's checking if the running profile allows to save order as legal appIsLegal = isLegalMode && ConfigManager.Instance.CommonConfiguration.PROFILES_LegalProgileID.Equals(profileKey); //closeResult = CloseCheque_profile(de.Key.ToString(), isLegalMode); profileResult = new Hashtable(); profileResult["PROFILE_ID"] = profileKey; profileResult["PROFILE_LAST"] = pIdx == ConfigManager.Instance.CommonConfiguration.PROFILES_Items.Count; /* close logic implementation */ // if this is a legal or in-between profile and there are other profiles // it requires to change payment info and set it without change // but las profile should has the rest and chnaged payment Dictionary<string, object> _tmpPaymanet = new Dictionary<string, object>(_orgPaymanet); _tmpPaymanet["CASHLIST"] = new List<double>((List<double>)_tmpPaymanet["CASHLIST"]); _tmpPaymanet["TYPE"] = new List<byte>((List<byte>)_tmpPaymanet["TYPE"]); if (_allProfiles.IndexOf(profileKey) + 1 < _allProfiles.Count) { _tmpPaymanet["SUMA"] = _realSUMA; ((List<double>)_tmpPaymanet["CASHLIST"])[0] = _realSUMA; _tmpPaymanet["REST"] = 0.0; // removing these values from original payment _orgPaymanet["SUMA"] = MathLib.GetRoundedMoney(MathLib.GetDouble(_orgPaymanet["SUMA"]) - _realSUMA); ((List<double>)_orgPaymanet["CASHLIST"])[0] = MathLib.GetRoundedMoney(MathLib.GetDouble(((List<double>)_orgPaymanet["CASHLIST"])[0]) - _realSUMA); } profileResult[CoreConst.PAYMENT] = _tmpPaymanet; profileResult[CoreConst.IS_LEGAL] = isLegalMode; localData = new object[8]; chqNom = string.Empty; localData[0] = clientID == string.Empty ? ConfigManager.Instance.CommonConfiguration.APP_ClientID : clientID; localData[1] = _discCommonPercent; localData[2] = _realSUMA; localData[3] = _taxSUMA; localData[4] = _fl_taxDocRequired; localData[5] = _fl_isReturnCheque; localData[6] = _fl_useTotDisc; //winapi.Funcs.OutputDebugString("B"); if (appIsLegal) { global::components.Components.WinApi.Com_WinApi.OutputDebugString("is legal cheque for profile " + currentProfileKey + " and legal profile is " + ConfigManager.Instance.CommonConfiguration.PROFILES_LegalProgileID); try { if (_fl_isReturnCheque) Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_PayMoney", _cheque, ConfigManager.Instance.CommonConfiguration.APP_DoseDecimals, _fl_useTotDisc, ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals); else Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_Sale", _cheque, ConfigManager.Instance.CommonConfiguration.APP_DoseDecimals, _fl_useTotDisc, ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals); if (_fl_useTotDisc && _discCommonPercent != 0.0) { Program.AppPlugins.GetActive<IFPDriver>().CallFunction( "FP_Discount", new object[] { (byte)2, _discCommonPercent, ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals, string.Empty } ); } if (lastPayment >= pMethod.Type.Count) lastPayment = 0; for (int i = lastPayment; i < pMethod.Type.Count; i++) { Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_Payment", pMethod.Type[i], ((List<double>)_tmpPaymanet["CASHLIST"])[i], true); lastPayment++; } chqNom = Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_LastChqNo", _fl_isReturnCheque).ToString(); localData[7] = Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_LastZRepNo", _fl_isReturnCheque); } catch (Exception ex) { CoreLib.WriteLog(ex, System.Reflection.MethodInfo.GetCurrentMethod().Name); MMessageBoxEx.Show(this.chequeDGV, "Помилка під час закриття чеку" + "\r\n" + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); uiWndChqNomRequest chqR = new uiWndChqNomRequest(); bool customOrderNo = false; if (chqR.ShowDialog(this.chequeDGV) == System.Windows.Forms.DialogResult.Yes) { customOrderNo = true; chqNom = chqR.ChequeNumber.ToString(); } chqR.Dispose(); if (!customOrderNo) return; } try { Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_OpenBox"); } catch (Exception ex) { MMessageBoxEx.Show(this.chequeDGV, "Помилка відкриття грошової скриньки" + "\r\n" + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); CoreLib.WriteLog(ex, System.Reflection.MethodInfo.GetCurrentMethod().Name); } } lastPayment = 0; chqNom = DataWorkCheque.SaveCheque(_cheque, localData, pMethod.Type[0], chqNom); profileResult[CoreConst.ORDER_NO] = chqNom; DataWorkShared.SetOrderProperty(_cheque, CoreConst.PAYMENT, _tmpPaymanet); DataWorkShared.SetOrderProperty(_cheque, CoreConst.ORDER_NO, chqNom); if (appIsLegal && UserConfig.Properties[10]) { DataWorkOutput.Print(Enums.PrinterType.OrderLegal, this.GetProfileOrder(profileKey)); } if (!appIsLegal && UserConfig.Properties[11]) { DataWorkOutput.Print(Enums.PrinterType.OrderNormal, this.GetProfileOrder(profileKey)); } fullResult.Add(profileResult); chqNumbers.Add(chqNom); chqNumbersFull.Add(appIsLegal ? chqNom : 'N' + chqNom); RowsRemoved_MyEvent_profile(profileKey); } catch { generalError = true; } if (generalError) break; } if (skippedProfiles == ConfigManager.Instance.CommonConfiguration.PROFILES_Items.Count) { MMessageBox.Show(this.chequeDGV, "Немає товарів для усіх профілів. Обновіть фільтри профілів.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); //UpdateSumInfo_profile(currentProfileKey, false); return; } if (generalError) { MMessageBox.Show(this.chequeDGV, "Виникла помилка під час збереження частини чеку.\r\nСпробуйте ще раз закрити чек", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); UpdateSumInfo_profile(currentProfileKey, false); return; } if (DataWorkShared.ExtractBillProperty(dtCopy, CoreConst.OID, string.Empty) != string.Empty) { //CoreLib.LockBill(this.PD_Order.Copy(), chqNom); if (ConfigManager.Instance.CommonConfiguration.Content_Bills_KeepAliveAfterCheque) { //string billChqNumFmt = string.Empty; //for (int cqnc = 0; cqnc < chqNumbers.Count; cqnc++) // billChqNumFmt += "{" + cqnc + "},"; //billChqNumFmt = billChqNumFmt.TrimEnd(','); //DataWorkBill.LockBill(dtCopy.Copy(), string.Format("[" + billChqNumFmt + "]", chqNumbers.ToArray())); DataWorkBill.LockBill(dtCopy.Copy(), string.Join(" | ", chqNumbersFull.ToArray())); } else DataWorkBill.BillDelete(dtCopy); //Cheque.ExtendedProperties["FXNO"] = chqNom; //File.Delete(Cheque.ExtendedProperties["PATH"].ToString()); } string closedInfo = string.Empty; if (chqNumbers.Count > 1) closedInfo = string.Format("{0} {1} ", "Закриті чеки №", string.Join(",", chqNumbers.ToArray())); else closedInfo = string.Format("{0} {1} ", "Закритий чек №", string.Join(string.Empty, chqNumbers.ToArray())); if (!string.IsNullOrEmpty(DataWorkShared.ExtractBillProperty(this.PD_Order, CoreConst.BILL_NO, string.Empty).ToString())) closedInfo += string.Format("{0} {1} ", "з рахунку №", DataWorkShared.ExtractBillProperty(this.PD_Order, CoreConst.BILL_NO, string.Empty)); RowsRemoved_MyEvent(false, true, true); CashLbl.ForeColor = ConfigManager.Instance.CommonConfiguration.STYLE_RestFontColor; CashLbl.Font = ConfigManager.Instance.CommonConfiguration.STYLE_RestFont; CashLbl.Text = string.Format("{0:F" + ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals + "}", pMethod.Rest); chequeInfoLabel.Text = string.Format("{0} {1:F" + ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals + "}", "залишок з суми", pMethod.CashSum); this.addBillInfo.Text = string.Empty; addChequeInfo.Text = closedInfo; if (isLegalMode && ConfigManager.Instance.CommonConfiguration.APP_ShowInfoOnIndicator) try { string[] lines = new string[2]; lines[0] = string.Format("{0} : {1:F" + ConfigManager.Instance.CommonConfiguration.APP_MoneyDecimals + "}", "Гроші", pMethod.CashSum); lines[1] = string.Format("{0} : {1}", "Здача", CashLbl.Text); bool[] show = new bool[] { true, true }; Program.AppPlugins.GetActive<IFPDriver>().CallFunction("FP_SendCustomer", lines, show); } catch { } //winapi.Funcs.OutputDebugString("E"); }