Beispiel #1
0
        public long AddReceive(receive receive)
        {
            try
            {
                //Get Party type Prefix by party Id :Kiron:27/10/2016

                var partyTypePrefix = (from ptype in _entities.party_type
                                       join par in _entities.parties on ptype.party_type_id equals par.party_type_id
                                       where par.party_id == receive.party_id
                                       select new
                {
                    party_prefix = ptype.party_prefix
                }).FirstOrDefault();

                int prnSerial = _entities.receives.Max(po => (int?)po.receive_id) ?? 0;

                if (prnSerial != 0)
                {
                    prnSerial++;
                }
                else
                {
                    prnSerial++;
                }
                var prnString = prnSerial.ToString().PadLeft(7, '0');


                string  prnNo          = "MRN-" + partyTypePrefix.party_prefix + "-" + prnString;
                receive insert_payment = new receive
                {
                    receipt_no           = prnNo,
                    receive_date         = System.DateTime.Now,//receive.receive_date,
                    party_id             = receive.party_id,
                    payment_method_id    = receive.payment_method_id,
                    cheque_no            = receive.cheque_no,
                    bank_id              = receive.bank_id,
                    bank_branch_id       = receive.bank_branch_id,
                    last_invoice_balance = receive.last_invoice_balance,
                    bank_account_id      = receive.bank_account_id,
                    amount              = receive.amount,
                    invoice_no          = receive.invoice_no,
                    representative      = receive.representative,
                    remarks             = receive.remarks,
                    payment_req_id      = receive.payment_req_id,
                    document_attachment = receive.document_attachment,
                    bank_charge         = receive.bank_charge,
                    is_varified         = receive.is_varified,
                    created_date        = System.DateTime.Now,
                    created_by          = receive.created_by,
                    is_active           = true,
                    is_deleted          = false,
                };
                _entities.receives.Add(insert_payment);
                long saved     = _entities.SaveChanges();
                long receiveId = insert_payment.receive_id;

                //mohi uddin(18.05.2017) start
                long rqId = 0;
                var  paymentRequestData = _entities.payment_request.Find(receive.payment_req_id);
                if (paymentRequestData != null)
                {
                    rqId = paymentRequestData.requisition_master_id ?? 0;
                    if (rqId != 0)
                    {
                        receive rcvData = _entities.receives.Find(receiveId);
                        rcvData.requisition_master_id = rqId;
                        _entities.SaveChanges();
                    }
                }
                //end(18.05.2017)

                if (saved > 0)
                {
                    PaymentRequestRepository paymentRequest = new PaymentRequestRepository();
                    paymentRequest.UpdateStatus(insert_payment.payment_req_id, insert_payment.created_by);
                }
                long last_insert_id = insert_payment.receive_id;
                return(last_insert_id);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }