Beispiel #1
0
        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (!IsValid())
            {
                return;
            }
            string _str = "Are You Sure You Want To Save This Record ??";

            ic.pledgeC _pledge = new MTOMS.ic.pledgeC();
            _pledge.amount_pledged = fGrid.Rows["pl_amount"].Cells[1].Value.ToInt32();
            ic.off_source_item _source = (fGrid.Rows["owner"].Cells[1].AuxValue as fnn.iGComboItemEX).Tag as ic.off_source_item;
            if (_source != null)
            {
                _pledge.source_id   = _source.source_id;
                _pledge.source_name = _source.source_name;
                _pledge.source_type = (em.off_source_typeS)_source.source_type_id;
            }

            if (fGrid.Rows["other_name"].Cells[1].Value != null)
            {
                _pledge.source_name = fGrid.Rows["other_name"].Cells[1].Value.ToStringNullable();
            }
            if (fGrid.Rows["other_phone"].Cells[1].Value != null)
            {
                _pledge.source_phone = fGrid.Rows["other_phone"].Cells[1].Value.ToStringNullable();
            }
            _pledge.fs_date = System.Convert.ToDateTime(fGrid.Rows["start_date"].Cells[1].AuxValue);

            _pledge.account_id = m_pledge_settings.account_id;
            _pledge.pls_id     = m_pledge_settings.pls_id;

            _pledge.pledge_mode   = em.pledge_modeS.normal;
            _pledge.pledge_status = em.pledge_statusS.pending;
            _pledge.fs_id         = fn.GetFSID(_pledge.fs_date);
            using (var xd = new xing())
            {
                var _e_pl = xd.ExecuteScalarInt(string.Format("select TOP 1 pl_id  from pledge_master_tb where source_id={0} and source_type_id={1} and pls_id={2} and pl_status<>{3}",
                                                              _pledge.source_id, _pledge.source_type.ToInt16(), _pledge.pls_id, em.pledge_statusS.deleted.ToInt16()));
                if (_e_pl > 0)
                {
                    MessageBox.Show("The Selected Member Already Made A Pledge To This Account !!", "Duplicate Pledge", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (!dbm.WarningMessage(_str, "Save Warning"))
                {
                    return;
                }
                _pledge.pl_id = xd.SingleInsertCommandTSPInt("pledge_master_tb", new string[]
                {
                    "account_id",
                    "source_type_id",
                    "source_id",
                    "source_name",
                    "source_phone",
                    "amount_pledged",
                    "amount_paid",
                    "exp_type",
                    "fs_time_stamp",
                    "pl_status",
                    "collect_date",
                    "fs_date",
                    "fs_id",
                    "pl_mode",
                    "lch_id",
                    "lch_type_id",
                    "pls_id",
                    "cg_id"
                }, new object[]
                {
                    _pledge.account_id,
                    _pledge.source_type.ToByte(),
                    _pledge.source_id,
                    _pledge.source_name,
                    _pledge.source_phone,
                    _pledge.amount_pledged,
                    _pledge.amount_paid,
                    emm.export_type.insert.ToByte(),
                    0,
                    _pledge.pledge_status.ToByte(),
                    _pledge.collect_date,
                    _pledge.fs_date,
                    _pledge.fs_id,
                    _pledge.pledge_mode.ToByte(),
                    datam.LCH_ID,
                    datam.LCH_TYPE_ID, _pledge.pls_id, _pledge.cg_id
                });
                accn.PledgeSummary(xd, _pledge.amount_pledged, _pledge.amount_paid, _pledge.pls_id);
                //
                var _retlist = (from k in datam.DATA_PENDING_PLEDGES.Values
                                where k.pls_id == _pledge.pls_id &
                                k.source_id == _pledge.source_id & k.source_type == _pledge.source_type
                                select k.pls_id).Count();
                if (_retlist == 0)
                {
                    var _pls = datam.DATA_CURRENT_PLEDGE_SETTINGS[_pledge.pls_id];
                    _str = string.Format("select amount,transaction_id,sab_date,off_id,pay_mode from off_accounts_tb where sab_fs_id between {0} and {1} and source_id={2} and source_type_id={3} and account_id={4} and receipt_status={5} order by sab_fs_id",
                                         _pls.start_fs_id, _pls.end_fs_id, _pledge.source_id, _pledge.source_type.ToByte(), _pledge.account_id, em.off_receipt_statusS.Valid.ToByte());
                    //
                    Correction.cr.cr_off_account        _off  = null;
                    List <Correction.cr.cr_off_account> _list = null;
                    using (var _dr = xd.SelectCommand(_str))
                    {
                        while (_dr.Read())
                        {
                            if (_list == null)
                            {
                                _list = new List <Correction.cr.cr_off_account>();
                            }
                            _off          = new Correction.cr.cr_off_account();
                            _off.amount   = _dr["amount"].ToInt32();
                            _off.trans_id = _dr["transaction_id"].ToInt64();
                            _off.fs_date  = _dr.GetDateTime("sab_date");
                            _off.off_id   = _dr["off_id"].ToInt32();
                            _off.pay_mode = (em.off_paymodeS)_dr["pay_mode"].ToByte();
                            _list.Add(_off);
                            _off = null;
                        }
                    }
                    if (_list != null)
                    {
                        #region old pledge payments
                        int ww_amount = 0;
                        _pledge.fs_date = _list.Min(k => k.fs_date);
                        _pledge.fs_id   = fn.GetFSID(_pledge.fs_date);
                        xd.SingleUpdateCommandALL("pledge_master_tb", new string[]
                                                  { "fs_date",
                                                    "fs_id", "pl_id" },
                                                  new object[]
                        {
                            _pledge.fs_date,
                            _pledge.fs_id,
                            _pledge.pl_id
                        }, 1);
                        foreach (var p in _list)
                        {
                            ww_amount = p.amount;
                            if (_pledge.balance <= ww_amount)
                            {
                                xd.SingleUpdateCommandALL("pledge_master_tb", new string[]
                                {
                                    "amount_paid",
                                    "pl_status",
                                    "fs_id",
                                    "pl_id",
                                }, new object[]
                                {
                                    _pledge.amount_pledged,
                                    em.pledge_statusS.completed.ToByte(),
                                    _pledge.fs_id,
                                    _pledge.pl_id
                                }, 2);
                                ww_amount -= _pledge.balance;

                                xd.SingleInsertCommandTSP("pledge_payment_mvt_tb", new string[]
                                {
                                    "off_id", "pl_id", "account_id", "fs_date", "fs_id", "amount", "pay_mode", "status", "lch_id", "lch_type_id", "source_type_id", "source_id", "transaction_id", "pl_fs_date", "pl_fs_id", "exp_type", "fs_time_stamp", "pls_id", "cg_id"
                                }, new object[] { p.off_id, _pledge.pl_id, _pledge.account_id, p.fs_date, fn.GetFSID(p.fs_date), _pledge.balance, p.pay_mode, 1, datam.LCH_ID, datam.LCH_TYPE_ID, _pledge.source_type.ToByte(), _pledge.source_id,
                                                  p.trans_id, _pledge.fs_date, _pledge.fs_id, 33, 0, _pledge.pls_id, _pledge.cg_id });
                                //

                                _pledge.amount_paid += _pledge.balance;
                                accn.PledgeSummary(xd, 0, _pledge.balance, _pledge.pls_id);
                            }
                            if (_pledge.balance > ww_amount)
                            {
                                xd.UpdateFsTimeStamp("pledge_master_tb");
                                xd.InsertUpdateDelete(string.Format("update pledge_master_tb set amount_paid=(amount_paid + {0}),fs_time_stamp={1},{2} where pl_id={3}",
                                                                    ww_amount, SQLH.UnixStamp, dbm.ETS, _pledge.pl_id));
                                xd.SingleInsertCommandTSP("pledge_payment_mvt_tb", new string[]
                                {
                                    "off_id", "pl_id", "account_id", "fs_date", "fs_id", "amount", "pay_mode", "status", "lch_id", "lch_type_id", "source_type_id", "source_id", "transaction_id", "pl_fs_date", "pl_fs_id", "exp_type", "fs_time_stamp", "pls_id", "cg_id"
                                }, new object[] { p.off_id, _pledge.pl_id, _pledge.account_id, p.fs_date, fn.GetFSID(p.fs_date), ww_amount, p.pay_mode, 1, datam.LCH_ID, datam.LCH_TYPE_ID, _pledge.source_type.ToByte(), _pledge.source_id,
                                                  p.trans_id, _pledge.fs_date, _pledge.fs_id, 33, 0, _pledge.pls_id, _pledge.cg_id });
                                //
                                _pledge.amount_paid += ww_amount;
                                accn.PledgeSummary(xd, 0, ww_amount, _pledge.pls_id);
                                ww_amount = 0;
                            }
                        }
                        #endregion
                    }
                }
                xd.CommitTransaction();
            }
            datam.GetPendingPledges();

            if (this.Owner is Pledge.PledgesManager)
            {
                (this.Owner as Pledge.PledgesManager).CheckUpdates();
            }
            if (this.Owner is Pledge.ViewPledgeMembers)
            {
                (this.Owner as Pledge.ViewPledgeMembers).NewRecord(_pledge);
            }
            var _drop_down_date = fGrid.Rows["start_date"].Cells[1].DropDownControl as fnn.DropDownCalenderX;
            if (_drop_down_date != null)
            {
                _drop_down_date.selected_date = _pledge.fs_date;// remember last date
            }
            buttonX2.PerformClick();
        }
        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (!IsValid())
            {
                return;
            }
            string _str    = "Are You Sure You Want To Save This Record ??";
            var    _date   = System.Convert.ToDateTime(fGrid.Rows["start_date"].Cells[1].AuxValue);
            int    _amount = fGrid.Rows["pl_amount"].Cells[1].Value.ToInt32();

            using (var xd = new xing())
            {
                if (!dbm.WarningMessage(_str, "Save Warning"))
                {
                    return;
                }
                xd.SingleInsertCommandTSPInt("pledge_addition_tb", new string[]
                {
                    "account_id",
                    "source_type_id",
                    "source_id",
                    "added_pledge_amount",
                    "pls_id",
                    "pl_id",
                    "fs_date",
                    "fs_id",
                    "lch_id",
                    "fs_time_stamp", "pl_status"
                }, new object[]
                {
                    m_pledge.account_id,
                    m_pledge.source_type.ToInt16(),
                    m_pledge.source_id,
                    _amount,
                    m_pledge.pls_id,
                    m_pledge.pl_id,
                    _date,
                    fn.GetFSID(_date),
                    datam.LCH_ID,
                    0,
                    em.pledge_setting_statusS.valid.ToInt16()
                });
                accn.PledgeSummary(xd, _amount, 0, m_pledge.pls_id);
                xd.SingleUpdateCommandALL("pledge_settings_tb", new string[]
                {
                    "paid_amount",
                    "pls_id"
                }, new object[]
                {
                    0,
                    m_pledge.pls_id
                }, 1);
                xd.UpdateFsTimeStamp("pledge_master_tb");
                _str = string.Format("update pledge_master_tb set added_pledge_amount=(added_pledge_amount + {0}),amount_pledged=(amount_pledged + {0}),amount_paid=0,fs_time_stamp={1},{2} where pl_id={3}",
                                     _amount, SQLH.UnixStamp, dbm.ETS, m_pledge.pl_id);
                xd.SingleUpdateCommand(_str);
                m_pledge.amount_paid          = 0;
                m_pledge.added_pledge_amount += _amount;
                m_pledge.amount_pledged      += _amount;
                SortedList <int, int> _vv_ids = new SortedList <int, int>();
                using (var _dr = xd.SelectCommand("select un_id,lch_id from pledge_payment_mvt_tb where pl_id=" + m_pledge.pl_id))
                {
                    while (_dr.Read())
                    {
                        _vv_ids.Add(_dr[0].ToInt32(), _dr[1].ToInt32());
                    }
                }
                foreach (var _d in _vv_ids)
                {
                    xd.SingleDeleteCommandExp("pledge_payment_mvt_tb", new string[] { "un_id", "lch_id" }, new int[] { _d.Key, _d.Value });
                }
                xd.CommitTransaction();
            }
            datam.GetPendingPledges();
            using (var xd = new xing())
            {
                var _pls = datam.DATA_CURRENT_PLEDGE_SETTINGS[m_pledge.pls_id];
                _str = string.Format("select amount,transaction_id,sab_date,off_id,pay_mode from off_accounts_tb where sab_fs_id between {0} and {1} and source_id={2} and source_type_id={3} and account_id={4} and receipt_status={5} order by sab_fs_id",
                                     _pls.start_fs_id, _pls.end_fs_id, m_pledge.source_id, m_pledge.source_type.ToByte(), m_pledge.account_id, em.off_receipt_statusS.Valid.ToByte());
                //
                Correction.cr.cr_off_account        _off  = null;
                List <Correction.cr.cr_off_account> _list = null;
                using (var _dr = xd.SelectCommand(_str))
                {
                    while (_dr.Read())
                    {
                        if (_list == null)
                        {
                            _list = new List <Correction.cr.cr_off_account>();
                        }
                        _off          = new Correction.cr.cr_off_account();
                        _off.amount   = _dr["amount"].ToInt32();
                        _off.trans_id = _dr["transaction_id"].ToInt64();
                        _off.fs_date  = _dr.GetDateTime("sab_date");
                        _off.off_id   = _dr["off_id"].ToInt32();
                        _off.pay_mode = (em.off_paymodeS)_dr["pay_mode"].ToByte();
                        _list.Add(_off);
                        _off = null;
                    }
                }
                if (_list != null)
                {
                    #region old pledge payments
                    int ww_amount = 0;

                    foreach (var p in _list)
                    {
                        ww_amount = p.amount;
                        if (m_pledge.balance <= ww_amount)
                        {
                            xd.SingleUpdateCommandALL("pledge_master_tb", new string[]
                            {
                                "amount_paid",
                                "pl_status",
                                "fs_id",
                                "pl_id",
                            }, new object[]
                            {
                                m_pledge.amount_pledged,
                                em.pledge_statusS.completed.ToByte(),
                                m_pledge.fs_id,
                                m_pledge.pl_id
                            }, 2);
                            ww_amount -= m_pledge.balance;

                            xd.SingleInsertCommandTSP("pledge_payment_mvt_tb", new string[]
                            {
                                "off_id", "pl_id", "account_id", "fs_date", "fs_id", "amount", "pay_mode", "status", "lch_id", "lch_type_id", "source_type_id", "source_id", "transaction_id", "pl_fs_date", "pl_fs_id", "exp_type", "fs_time_stamp", "pls_id", "cg_id"
                            }, new object[] { p.off_id, m_pledge.pl_id, m_pledge.account_id, p.fs_date, fn.GetFSID(p.fs_date), m_pledge.balance, p.pay_mode, 1, datam.LCH_ID, datam.LCH_TYPE_ID, m_pledge.source_type.ToByte(), m_pledge.source_id,
                                              p.trans_id, m_pledge.fs_date, m_pledge.fs_id, 33, 0, m_pledge.pls_id, m_pledge.cg_id });
                            //
                            m_pledge.amount_paid += m_pledge.balance;
                            accn.PledgeSummary(xd, 0, m_pledge.balance, m_pledge.pls_id);
                        }
                        if (m_pledge.balance > ww_amount)
                        {
                            xd.UpdateFsTimeStamp("pledge_master_tb");
                            xd.InsertUpdateDelete(string.Format("update pledge_master_tb set amount_paid=(amount_paid + {0}),fs_time_stamp={1},{2} where pl_id={3}",
                                                                ww_amount, SQLH.UnixStamp, dbm.ETS, m_pledge.pl_id));
                            xd.SingleInsertCommandTSP("pledge_payment_mvt_tb", new string[]
                            {
                                "off_id", "pl_id", "account_id", "fs_date", "fs_id", "amount", "pay_mode", "status", "lch_id", "lch_type_id", "source_type_id", "source_id", "transaction_id", "pl_fs_date", "pl_fs_id", "exp_type", "fs_time_stamp", "pls_id", "cg_id"
                            }, new object[] { p.off_id, m_pledge.pl_id, m_pledge.account_id, p.fs_date, fn.GetFSID(p.fs_date), ww_amount, p.pay_mode, 1, datam.LCH_ID, datam.LCH_TYPE_ID, m_pledge.source_type.ToByte(), m_pledge.source_id,
                                              p.trans_id, m_pledge.fs_date, m_pledge.fs_id, 33, 0, m_pledge.pls_id, m_pledge.cg_id });
                            //
                            m_pledge.amount_paid += ww_amount;
                            accn.PledgeSummary(xd, 0, ww_amount, m_pledge.pls_id);
                            ww_amount = 0;
                        }
                    }
                    #endregion
                }
                xd.CommitTransaction();
            }
            datam.GetPendingPledges();
            buttonX2.PerformClick();
            this.Tag = null;
            this.Close();
        }