function calcWokrs( &$works = array(), $toProgramID ){ $price = 0; $discounts = getDiscounts2( $toProgramID ); foreach ( $works as $id => &$data ){ $curdiscount = 1; if( isset ( $discounts[ $data["PROPERTY_J_SERVICE_VALUE"]] ) ){ $arDiscountInfo = current( $discounts[$data["PROPERTY_J_SERVICE_VALUE"]]); $curdiscount = ( 100 - $arDiscountInfo["VALUE"] )/100; $data ["DISCOUNT_NAME"] = $arDiscountInfo["NAME"]; } $data ["WORK_COST"] = $curdiscount * $data ["PROPERTY_J_PRICE_VALUE"] * $data ["PROPERTY_J_COUNT_VALUE"]; $data ["TRUE_COST"] = $data ["PROPERTY_J_PRICE_VALUE"] * $data ["PROPERTY_J_COUNT_VALUE"]; $price = ( float )$price + $data ["WORK_COST"]; } return $price; }
function calcCostTOWorks( &$arTO ){ $discounts = getDiscounts2(); $arWokrTypes = GetWorkTypes(); $TYPE_COST = array(); foreach( $arTO as $name=>&$TOData ){ $price = 0; $arWorksByType = array(); /* foreach ( $TOData["work"] as $id => &$data ){ $curdiscount = 1; // print_r( $arDiscountInfo ); if( isset ( $discounts[ $data["PROPERTY_J_SERVICE_VALUE"]] ) ){ $arDiscountInfo = current( $discounts[$data["PROPERTY_J_SERVICE_VALUE"]]); $arDiscountInfo["VALUE"]; //sort( $discounts[ $data["PROPERTY_J_SERVICE_VALUE"] ] ); $curdiscount = ( 100 - $arDiscountInfo["VALUE"] )/100; $data ["DISCOUNT_NAME"] = $arDiscountInfo["NAME"]; } $data ["WORK_COST"] = $curdiscount * $data ["PROPERTY_J_PRICE_VALUE"] * $data ["PROPERTY_J_COUNT_VALUE"]; $data ["TRUE_COST"] = $data ["PROPERTY_J_PRICE_VALUE"] * $data ["PROPERTY_J_COUNT_VALUE"]; //echo "real cost : ", $data ["TRUE_COST"], "\t cost with discount: ", $data ["WORK_COST"],"\n"; $price = ( float )$price + $data ["WORK_COST"]; $arWorksByType [ $data ['PROPERTY_J_SERVICE_IBLOCK_SECTION_ID'] ] = array ( "NAME" => $arWokrTypes [ $data ['PROPERTY_J_SERVICE_IBLOCK_SECTION_ID'] ], "COST"=>( $arWorksByType[ $data['PROPERTY_J_SERVICE_IBLOCK_SECTION_ID']] ["COST"] + $data ["WORK_COST"] ) ); } */ $price = calcWokrs ( $TOData["work"] ); $TOData["COST"] = $price; $TOData["TYPE_COST"] = $arWorksByType; } }