Exemplo n.º 1
0
 public object Save([FromBody] MS_ACCT_TXN_DOC document)
 {
     try
     {
         TxnDocMdl.Save(document);
         return(new { state = true, message = "Txn Document Successfully Generated" });
     }
     catch (Exception e)
     {
         return(e);
     }
 }
Exemplo n.º 2
0
        public static bool Save(MS_ACCT_TXN_DOC document)
        {
            try
            {
                var _db   = new SibaModel();
                var dbDoc = _db.MS_ACCT_TXN_DOC.Find(document.ATD_CODE);
                switch (document.ATD_STATUS)
                {
                case "A":
                    if (dbDoc != null)
                    {
                        _db.MS_ACCT_TXN_DOC.Attach(dbDoc);
                        dbDoc.Map(document);
                        dbDoc.ATD_MOD_DATE = DateTime.Now;

                        /*-------------------------------------------------
                         * txn document document no  generation processing
                         *-----------------------------------------------*/
                        foreach (var gen in document.MS_ACT_DOC_NO_GEN)
                        {
                            var dbGen   = _db.MS_ACT_DOC_NO_GEN.Find(gen.DNG_SYS_ID);
                            var seqName = document.ATD_CODE + "_" + gen.DNG_ACNT_YEAR;
                            switch (gen.DNG_STATUS)
                            {
                            case "A":
                                if (dbGen != null)
                                {
                                    _db.MS_ACT_DOC_NO_GEN.Attach(dbGen);
                                    dbGen.Map(gen);
                                    dbGen.DNG_MOD_DATE = DateTime.Now;

                                    var curNo = _db.Database.SqlQuery <int>("SELECT " + seqName + ".NEXTVAL FROM DUAL").Single();

                                    //update seqeuence for the document no. generation
                                    procCntx.SEQ_CREATOR4(seqName, curNo, gen.DNG_CUR_NO, gen.DNG_END_NO, 20, gen.DNG_NXT_NO);
                                }
                                break;

                            case "U":
                                gen.DNG_STATUS    = "A";
                                gen.DNG_ATD_CODE  = document.ATD_CODE;
                                gen.DNG_CRTE_DATE = DateTime.Now;

                                //generate seqeuence for the document no. generation
                                procCntx.SEQ_CREATOR3(seqName, gen.DNG_STRT_NO, gen.DNG_CUR_NO, gen.DNG_END_NO, 20, gen.DNG_NXT_NO);
                                _db.MS_ACT_DOC_NO_GEN.Add(gen);

                                break;

                            case "D":
                                if (dbGen != null)
                                {
                                    _db.MS_ACT_DOC_NO_GEN.Attach(dbGen);
                                    dbGen.DNG_STATUS   = "D";
                                    dbGen.DNG_MOD_DATE = DateTime.Now;
                                }
                                break;
                            }
                        }


                        /*--------------------------------------
                         * txn document default accounts setup
                         *------------------------------------*/
                        foreach (var defAcnt in document.MS_ACT_DEF_ACNTS)
                        {
                            var dbDefAcnt = _db.MS_ACT_DEF_ACNTS.Find(defAcnt.DA_SYS_ID);
                            switch (defAcnt.DA_STATUS)
                            {
                            case "A":
                                if (dbDefAcnt != null)
                                {
                                    _db.MS_ACT_DEF_ACNTS.Attach(dbDefAcnt);
                                    dbDefAcnt.Map(defAcnt);
                                    dbDefAcnt.DA_MOD_DATE = DateTime.Now;
                                }
                                break;

                            case "U":
                                defAcnt.DA_STATUS    = "A";
                                defAcnt.DA_ATD_CODE  = document.ATD_CODE;
                                defAcnt.DA_CRTE_DATE = DateTime.Now;

                                _db.MS_ACT_DEF_ACNTS.Add(defAcnt);
                                break;

                            case "D":
                                if (dbDefAcnt != null)
                                {
                                    _db.MS_ACT_DEF_ACNTS.Attach(dbDefAcnt);
                                    dbDefAcnt.DA_STATUS   = "D";
                                    dbDefAcnt.DA_MOD_DATE = DateTime.Now;
                                }
                                break;
                            }
                        }


                        /*--------------------------------------
                         * txn document default accounts setup
                         *------------------------------------*/
                        foreach (var rights in document.MS_ACT_TXN_DOC_ACCS_RGHTS)
                        {
                            var dbRights = _db.MS_ACT_TXN_DOC_ACCS_RGHTS.Find(rights.TDAR_SYS_ID);
                            switch (rights.TDAR_STATUS)
                            {
                            case "A":
                                if (dbRights != null)
                                {
                                    _db.MS_ACT_TXN_DOC_ACCS_RGHTS.Attach(dbRights);
                                    dbRights.Map(rights);
                                    dbRights.TDAR_MOD_DATE = DateTime.Now;
                                }
                                break;

                            case "U":
                                rights.TDAR_STATUS    = "A";
                                rights.TDAR_ATD_CODE  = document.ATD_CODE;
                                rights.TDAR_CRTE_DATE = DateTime.Now;

                                _db.MS_ACT_TXN_DOC_ACCS_RGHTS.Add(rights);
                                break;

                            case "D":
                                if (dbRights != null)
                                {
                                    _db.MS_ACT_TXN_DOC_ACCS_RGHTS.Attach(dbRights);
                                    dbRights.TDAR_STATUS   = "D";
                                    dbRights.TDAR_MOD_DATE = DateTime.Now;
                                }
                                break;
                            }
                        }


                        /*--------------------------------------
                         * txn document default accounts setup
                         *------------------------------------*/
                        foreach (var props in document.MS_ACT_TXN_DOC_ADV_PROPS)
                        {
                            var dbProps = _db.MS_ACT_TXN_DOC_ADV_PROPS.Find(props.DAP_SYS_ID);
                            switch (props.DAP_STATUS)
                            {
                            case "A":
                                if (dbProps != null)
                                {
                                    _db.MS_ACT_TXN_DOC_ADV_PROPS.Attach(dbProps);
                                    dbProps.Map(props);
                                    dbProps.DAP_MOD_DATE = DateTime.Now;
                                }
                                break;

                            case "U":
                                props.DAP_STATUS    = "A";
                                props.DAP_ATD_CODE  = document.ATD_CODE;
                                props.DAP_CRTE_DATE = DateTime.Now;

                                _db.MS_ACT_TXN_DOC_ADV_PROPS.Add(props);
                                break;

                            case "D":
                                break;
                            }
                        }
                    }
                    break;

                case "U":
                    document.ATD_STATUS    = "A";
                    document.ATD_CRTE_DATE = DateTime.Now;

                    document.MS_ACT_TXN_DOC_ACCS_RGHTS.ForEach(x => { x.TDAR_STATUS = "A"; x.TDAR_CRTE_DATE = DateTime.Now; });
                    document.MS_ACT_DEF_ACNTS.ForEach(x => { x.DA_STATUS = "A"; x.DA_CRTE_DATE = DateTime.Now; });
                    document.MS_ACT_DOC_NO_GEN.ForEach(x =>
                    {
                        x.DNG_STATUS    = "A";
                        x.DNG_CRTE_DATE = DateTime.Now;
                        //generate seqeuence for the document no. generation
                        var seqName = document.ATD_CODE + "_" + x.DNG_ACNT_YEAR;

                        procCntx.SEQ_CREATOR3(seqName, x.DNG_STRT_NO, x.DNG_CUR_NO, x.DNG_END_NO, 20, x.DNG_NXT_NO);
                    });
                    document.MS_ACT_TXN_DOC_ADV_PROPS.ForEach(x => x.DAP_STATUS = "A");

                    _db.MS_ACCT_TXN_DOC.Add(document);
                    break;

                case "D":
                    if (dbDoc != null)
                    {
                        _db.MS_ACCT_TXN_DOC.Attach(dbDoc);
                        dbDoc.ATD_STATUS   = "D";
                        dbDoc.ATD_MOD_DATE = DateTime.Now;
                    }
                    break;
                }

                return(_db.SaveChanges() > 0);
            }
            catch (Exception)
            {
                throw;
            }
        }