00001 #include <QMessageBox> 00002 #include <QDebug> 00003 #include "costunitproduct.h" 00004 00005 CostUnitProduct::CostUnitProduct() 00006 { 00007 //qDebug()<<"TEMPORARY: added costcentres and fileid hardcoded for surcharges -- CostUnitProduct"; 00008 p_costcentreIDs<<0; 00009 p_costcentreIDs<<2; 00010 p_fileIdCostCentre = 1; 00011 00012 p_directcosts = 0; 00013 p_markup = 0; 00014 p_commission = 0; 00015 p_tradediscount = 0; 00016 p_discount = 0; 00017 p_salestax = 0; 00018 } 00019 00020 void CostUnitProduct::setProductData(QString textDirectCosts, QString textMarkup, QString textCommission, QString textTradeDiscount, QString textDiscount, QString textSalesTax) 00021 { 00022 if(textDirectCosts.toDouble()>0 && textMarkup.toDouble()>=0 && textCommission.toDouble()>=0 && textTradeDiscount.toDouble()>=0 && textDiscount.toDouble()>=0 && textSalesTax.toDouble()>=0) 00023 { 00024 p_directcosts = textDirectCosts.toDouble(); 00025 p_markup = textMarkup.toDouble(); 00026 p_commission = textCommission.toDouble(); 00027 p_tradediscount = textTradeDiscount.toDouble(); 00028 p_discount = textDiscount.toDouble(); 00029 p_salestax = textSalesTax.toDouble(); 00030 } 00031 else 00032 { 00033 QMessageBox::warning(NULL, tr("Fehler"), tr("Ihre Eingabe ist fehlerhaft!")); 00034 return ; 00035 } 00036 } 00037 00038 QList<double> CostUnitProduct::dataList() 00039 { 00040 QList<double> items; 00041 items<<productionCosts(); 00042 items<<profitCalculation(); 00043 items<<commissionCalculation(); 00044 items<<discountCalculation(); 00045 items<<salesDiscountCalculation(); 00046 items<<salesTaxCalculation(); 00047 00048 return items; 00049 } 00050 00051 QList<double> CostUnitProduct::userList() 00052 { 00053 QList<double> items; 00054 items<<p_directcosts; 00055 items<<p_markup; 00056 items<<p_commission; 00057 items<<p_tradediscount; 00058 items<<p_discount; 00059 items<<p_salestax; 00060 00061 return items; 00062 } 00063 00064 double CostUnitProduct::productionCosts() 00065 { 00066 double sk = p_directcosts; 00067 00068 //qDebug()<<"TODO: CostUnitProduct -- Add surcharges"; 00069 00070 /* 00071 Search through the file specified by the fileid for the costcentres specified in the costcentre_ids, add them to the price and return the price 00072 */ 00073 /*for(int j=0;j<zuschlaege.size();j++) 00074 { 00075 if(zuschlaege.value(j).endsWith("")) 00076 { 00077 QString zuschlag = zuschlaege.value(j); 00078 zuschlag = zuschlag.remove(""); 00079 double z = zuschlag.toDouble(); 00080 sk = z; 00081 } 00082 else 00083 { 00084 QString zuschlag = zuschlaege.value(j); 00085 zuschlag = zuschlag.remove("%"); 00086 double z = zuschlag.toDouble(); 00087 sk += sk*(z/100); 00088 } 00089 }*/ 00090 return sk; 00091 } 00092 00093 double CostUnitProduct::profitCalculation() 00094 { 00095 return productionCosts() * (p_markup / 100); 00096 } 00097 00098 double CostUnitProduct::netSalesPrice() 00099 { 00100 return productionCosts() + profitCalculation(); 00101 } 00102 00103 double CostUnitProduct::commissionCalculation() 00104 { 00105 return p_commission * (netSalesPrice() / (100 - p_commission)); 00106 } 00107 00108 double CostUnitProduct::cashPrice() 00109 { 00110 return netSalesPrice() + commissionCalculation(); 00111 } 00112 00113 double CostUnitProduct::discountCalculation() 00114 { 00115 return p_tradediscount * (cashPrice() / (100 - p_tradediscount)); 00116 } 00117 00118 double CostUnitProduct::targetPrice() 00119 { 00120 return cashPrice() + discountCalculation(); 00121 } 00122 00123 double CostUnitProduct::salesDiscountCalculation() 00124 { 00125 return p_discount * (targetPrice() / (100 - p_discount)); 00126 } 00127 00128 double CostUnitProduct::grossSalesPriceWithoutSalesTax() 00129 { 00130 return targetPrice() + salesDiscountCalculation(); 00131 } 00132 00133 double CostUnitProduct::salesTaxCalculation() 00134 { 00135 return p_salestax / 100 * grossSalesPriceWithoutSalesTax(); 00136 } 00137 00138 double CostUnitProduct::grossSalesPriceWithSalesTax() 00139 { 00140 return grossSalesPriceWithoutSalesTax() + salesTaxCalculation(); 00141 } 00142