Example #1
0
        public void Submit(long procurementID)
        {
            var entity = repository.GetProcurement(procurementID);

            if (entity == null)
            {
                throw new LogicException("提交編號不存在");
            }

            if (entity.State != ProcurementState.Save)
            {
                throw new LogicException("当前状态不能提交!");
            }

            var files = repository.GetProcurementFiles(procurementID);

            if (files.IsEmpty())
            {
                throw new LogicException("審批文件爲空");
            }
            var items = repository.GetProcurementBQItems(procurementID);

            if (items.IsEmpty() && entity.ProcurementType != ProcurementType.Paid)
            {
                throw new LogicException("BQ明細爲空");
            }
            var calculation = repository.GetCalculation(entity.ProjectId);

            entity.State = ProcurementState.Submit;
            repository.UpdateProcurement(entity);

            switch (entity.ProcurementType)
            {
            case ProcurementType.Materials:
            {
                calculation.MaterialCost += entity.ThisProcurementAmount;
                break;
            }

            case ProcurementType.Outsourcing:
            {
                var calculationItem = new ProjectCalculationDetail()
                {
                    ProcurementId     = procurementID,
                    ProjectId         = entity.ProjectId,
                    ContractAmount    = entity.ItemAmount,
                    ProcurementAmount = entity.ProcurementAmount,
                    EstimateCost      = entity.OtherAmount,
                    Remark            = entity.Remark,
                    GrossMargin       = entity.ProfitsRate
                };
                calculationItem.Created(this);

                repository.AddCalculationDetail(calculationItem);
                //   if (entity.TotalPurchaseAmount <= 0) throw new BingoX.LogicException("總採購金額 不爲正數");
                break;
            }

            case ProcurementType.Other:
            {
                calculation.MangerCost += entity.ThisProcurementAmount;
                break;
            }

            case ProcurementType.Paid:
            {
                calculation.MangerCost += entity.PaidAmount;
                //  if (entity.TotalPurchaseAmount <= 0) throw new BingoX.LogicException("總採購金額 不爲正數");
                break;
            }

            default:
                break;
            }
            repository.UnitOfWork.Commit();
        }
 public void AddCalculationDetail(ProjectCalculationDetail entity)
 {
     dataAccessorProjectCalculationDetail.Add(entity);
 }