@foreach ($contributors1 as $contributordet)@endforeach $calc){ $gross_sales = 0; $total_qty = 0; foreach($calc as $book_name => $market_details){ if ($iterations >= 1) { echo ""; echo"
"; }else{ echo "";echo"
"; } #contributor name and quarter // echo '
Contributor Name : '.$contributordet["user_details"]["name"].'
'; // echo '
Quarter :'.$selected_q.'- '.$selected_year.'
'; // echo "

BOOK TITLE : ".strstr($book_name, '-varprice-', true)."
"; echo '

'; echo ''; echo ''; echo ""; ##DIGITAL PRICE AND PRINT PRINT## #get everything between varprice and digiprice to fetch the print price if (preg_match('/-varprice-(.*?)-digiprice-/', $book_name, $match) == 1) { $var_price = $match[1]; } if(empty($var_price)){ $var_price = 0; } if(is_float($var_price) == false){ $var_price= floatval($var_price); }else{ $var_price = $var_price; } $var_price = money_format('%+n', $var_price); //echo "PRINT PRICE : ".$var_price."
"; echo ""; #fetch the digital price $digiprice = explode('-digiprice-', $book_name, 2)[1]; if(!empty($digiprice)){ if(is_float($digiprice) == false){ $digiprice= floatval($digiprice); }else{ $digiprice = $digiprice; } $digiprice = money_format('%+n', $digiprice); // echo "DIGITAL PRICE : ".$digiprice."

"; echo ""; } ##OUT OF PRINT## if(isset($out_print_array[$book_no1])){ foreach($out_print_array[$book_no1] as $key_id => $things){ if($things['year']==$selected_year){ $q_arr = explode(',', $things['quarters']); if(in_array($selected_quarter, $q_arr)){ // echo "
NOTE: Item Out of print for ".$selected_q."

"; echo "Item Out of print for ".$selected_q." "; } } } } echo '
Company Logo Contributor Name'.$contributordet["user_details"]["name"].'
Quarter'.$selected_q.'- '.$selected_year.'
Book Title".strstr($book_name, '-varprice-', true)."
Print Price".$var_price."
Digital Price".$digiprice."
NOTE
'; ##SALES TABLE## echo ''; #direct echo ""; $net_direct_qty = $market_details['DIRECT_MARKET_STORES']['qty_sold']+$market_details['DIRECT_SHORTAGE_/_DAMAGE']['qty_sold']+$market_details['DIRECT_RETURNS']['qty_sold']; $net_direct_revenue = ($market_details['DIRECT_MARKET_STORES']['total_cost'])+( $market_details['DIRECT_SHORTAGE_/_DAMAGE']['total_cost'])+( $market_details['DIRECT_RETURNS']['total_cost']); echo ""; if(is_float($net_direct_revenue) == false){ $net_direct_qty1= floatval($net_direct_revenue); }else{ $net_direct_qty1 = $net_direct_revenue; } $net_direct_qty1 = money_format('%+n', $net_direct_qty1); echo ""; #non_direct echo ""; $net_non_dir_qty = $market_details['NON-DIRECT_MARKET_STORES']['qty_sold']+$market_details['NON-DIRECT_SHORTAGE']['qty_sold']; $net_non_dir_revenue = ($market_details['NON-DIRECT_MARKET_STORES']['total_cost'])+( $market_details['NON-DIRECT_SHORTAGE']['total_cost']); echo ""; if(is_float($net_non_dir_revenue) == false){ $net_non_dir_revenue1= floatval($net_non_dir_revenue); }else{ $net_non_dir_revenue1 = $net_non_dir_revenue; } $net_non_dir_revenue1 = money_format('%+n', $net_non_dir_revenue1); echo ""; #returns echo ""; $return_qty = $market_details['NON-DIRECT_RETURNS']['qty_sold']; $return_revenue = $market_details['NON-DIRECT_RETURNS']['unit_retails'] * $market_details['NON-DIRECT_RETURNS']['qty_sold'] * 3/100 ; $net_return = $market_details['NON-DIRECT_RETURNS']['unit_retails']*(1-($market_details['NON-DIRECT_RETURNS']['discount']/100)) * $market_details['NON-DIRECT_RETURNS']['qty_sold'] + $return_revenue; echo ""; if(is_float($net_return) == false){ $return_revenue1= floatval($net_return); }else{ $return_revenue1 = $net_return; } $return_revenue1 = money_format('%+n', $return_revenue1); echo ""; #international echo ""; $net_internatioal_revenue = $market_details['INTERNATIONAL_NON-DIRECT_MARKET_STORES']['unit_retails']*$market_details['INTERNATIONAL_NON-DIRECT_MARKET_STORES']['qty_sold']*(1-($market_details['INTERNATIONAL_NON-DIRECT_MARKET_STORES']['discount']/100))- ($market_details['INTERNATIONAL_NON-DIRECT_MARKET_STORES']['unit_retails']*$market_details['INTERNATIONAL_NON-DIRECT_MARKET_STORES']['qty_sold']*(2.5/100))+($market_details['INTERNATIONAL_NON-DIRECT_MARKET_SHORTAGES']['unit_retails']*(1-($market_details['INTERNATIONAL_NON-DIRECT_MARKET_SHORTAGES']['discount']/100))*$market_details['INTERNATIONAL_NON-DIRECT_MARKET_SHORTAGES']['qty_sold']); $net_internatioal_qty = $market_details['INTERNATIONAL_NON-DIRECT_MARKET_STORES']['qty_sold']+$market_details['INTERNATIONAL_NON-DIRECT_MARKET_SHORTAGES']['qty_sold']; echo ""; if(is_float($net_internatioal_revenue) == false){ $net_internatioal_revenue1= floatval($net_internatioal_revenue); }else{ $net_internatioal_revenue1 = $net_internatioal_revenue; } $net_internatioal_revenue1 = money_format('%+n', $net_internatioal_revenue1); echo ""; #digital if($market_details['digital_sales'] != 0 && $market_details['digital_sales'] != ""){ echo ""; echo ""; if(is_float($market_details['digital_sales']) == false){ $digi_sales= floatval($market_details['digital_sales']); }else{ $digi_sales = $market_details['digital_sales']; } echo ""; } #Oni sales echo ""; echo ""; if(is_float($market_details['oni_sales']) == false){ $oni__sales= floatval($market_details['oni_sales']); }else{ $oni__sales = $market_details['oni_sales']; } echo ""; # s & s sales echo ""; echo ""; if(is_float($market_details['ss_sales']) == false){ $ss__sales= floatval($market_details['ss_sales']); }else{ $ss__sales = $market_details['ss_sales']; } echo ""; #totals $gross_sales = $net_return+$net_non_dir_revenue+$net_direct_revenue+$net_internatioal_revenue+$market_details['digital_sales']+$market_details['oni_sales']+$market_details['ss_sales']; $total_qty = $net_direct_qty+$net_non_dir_qty+$return_qty+$net_internatioal_qty+$market_details['digital_qty']+$market_details['oni_qty']+$market_details['ss_qty']; ##TOTAL QUANTITY## echo ""; echo ""; ##TOTAL GROSS SALES if(is_float($gross_sales) == false){ $gross_sales_val= floatval($gross_sales); }else{ $gross_sales_val = $gross_sales; } $gross_sales_value = money_format('%+n', $gross_sales_val); echo ""; echo '
Sales OutletNet Qty SoldRevenue
Direct Market Sales";echo $net_direct_qty."";echo $net_direct_qty1."
Non-Direct Market Sales";echo $net_non_dir_qty."";echo $net_non_dir_revenue1 ."
Non-Direct Market Returns";echo $return_qty."";echo $return_revenue1; echo "
International Sales";echo $net_internatioal_qty."";echo $net_internatioal_revenue1; echo "
Digital Sales";echo $market_details['digital_qty']."";echo money_format('%+n', $digi_sales)."
Retail (Oni Press)";echo $market_details['oni_qty']."";echo money_format('%+n', $oni__sales)."
Simon & Schuster Sales";echo $market_details['ss_qty']."";echo money_format('%+n', $ss__sales)."
Total";echo $total_qty."";echo $gross_sales_value."
'; } #to add page break before the week , it will add page new page for reach book for the iterations greater than or equal to 1 #total expense foreach( $contributordet['book_details']['expense'] as $book_no_expense => $book_id_expense){ //echo"
 book_id_expense ";print_r($book_id_expense);
			if( $book_no1 == $book_no_expense ) {
				foreach($book_id_expense as $more_singledet){


					if ($selected_year==$more_singledet['year']) { 
					#to select quarter for selected year

						if (in_array($more_singledet['book_id'], $quarter_value)) {
					    continue;
						}
					    $quarter_value[] = $more_singledet['book_id'];

					   	##collecting name and quarter expense in main_quarter array

					    if($selected_quarter == 1){
							$main_quarter[$book_no1][]= array(
							$more_singledet['book_title'],
							$more_singledet['first_quarter']
							);
							$this_quarter = '1st Quarter (Jan-March)';
						}

						if($selected_quarter == 2){
							$main_quarter[$book_no1][]= array(
							$more_singledet['book_title'],
							$more_singledet['second_quarter']
							);
							$this_quarter = '2nd Quarter (Apr-June)';
						}

						if($selected_quarter == 3){
							$main_quarter[$book_no1][]= array(
							$more_singledet['book_title'],
							$more_singledet['third_quarter']
							);
							$this_quarter = '3rd Quarter (July-Sept)';
						}

						if($selected_quarter == 4){
							$main_quarter[$book_no1][]= array(
							$more_singledet['book_title'],
							$more_singledet['fourth_quarter']
							);
							$this_quarter = '4th Quarter (Oct-Dec)';
						}
						if($selected_quarter == 5) {
							$all_qtr_val = array(); #not used
							$all_qtr_sum =0;
							foreach($qtrs_val as $qtr){
								if($qtr == 1){
									$all_qtr_sum +=$more_singledet['first_quarter'];
								}
								if($qtr == 2){
									$all_qtr_sum +=$more_singledet['second_quarter'];
								}
								if($qtr == 3){
									$all_qtr_sum +=$more_singledet['third_quarter'];
								}
								if($qtr == 4){
									$all_qtr_sum +=$more_singledet['fourth_quarter'];
								}
							}
							$main_quarter[$book_no1][]= array(
							$more_singledet['book_title'],
							$all_qtr_sum
							);
							$this_quarter = 'CUSTOM QUARTER ('.$month_name1.'-'.$month_name2.')';
						}
					}
				}
			}
		}

		if(!array_key_exists($book_no1,$main_quarter)){
			$main_quarter[$book_no1][]= array(
			strstr($book_name, '-varprice-', true),0
			);
			if( $selected_quarter == 1){
				$this_quarter = '1st Quarter (Jan-March)';
			}elseif( $selected_quarter == 2){
				$this_quarter = '2nd Quarter (Apr-June)';
			}elseif( $selected_quarter == 3){
				$this_quarter = '3rd Quarter (July-Sept)';
			}elseif( $selected_quarter == 4){
				$this_quarter = '4th Quarter (Oct-Dec)';
			}elseif( $selected_quarter == 5){
				$this_quarter = 'Custom Quarter Selected';
			}
		}

		##EXPENSE##
		//echo'

QUALIFIED EXPENSES, '.$this_quarter.'

'; echo'
QUALIFIED EXPENSES, '.$this_quarter.'
'; echo ''; foreach($main_quarter[$book_no1] as $t_q){ echo""; foreach($t_q as $t){ #if no quarter value if($t==""){ $sum = $t; echo""; }else{ if(is_numeric($t)){ if(is_float($t) == false){ $t_val= floatval($t); }else{ $t_val = $t; } $t_val_value = money_format('%+n', $t_val); echo""; $sum = $t; }else{ echo""; } } } } // echo '
Book Title Amount
$0" .$t_val_value."" .$t."
'; echo ''; #ROYALTY CHOICE CHECKS if($contributordet["book_details"]["royalty_choice"][$book_no1] == NULL || $contributordet["book_details"]["royalty_choice"][$book_no1] == 1){ $r_choice = "Net"; } if($contributordet["book_details"]["royalty_choice"][$book_no1] == 2){ $r_choice = "Gross"; } if($contributordet["book_details"]["royalty_choice"][$book_no1] == 3){ $r_choice = "Cover Price"; } ##ROYALTY CHOICE VALUE //echo "
ROYALTY CHOICE : ".$r_choice."
"; echo ''; echo ""; ##TOTAL QTY // echo " TOTAL QUANTITY SOLD THIS QUARTER : ";echo $total_qty."
"; echo ""; #GROSS SALE if(is_float($gross_sales) == false){ $gross_sales_val= floatval($gross_sales); }else{ $gross_sales_val = $gross_sales; } $gross_sales_value = money_format('%+n', $gross_sales_val); // echo "TOTAL GROSS SALES THIS QUARTER : ";echo $gross_sales_value."
"; echo ""; #TOTAL EXPENSES if(is_float($sum) == false){ $sum_float= floatval($sum); }else{ $sum_float = $sum; } $sumvalue = money_format('%+n', $sum_float); // echo "TOTAL EXPENSES THIS QUARTER: ". $sumvalue."
"; echo ""; #Total Profit : #royalty check : net if($contributordet["book_details"]["royalty_choice"][$book_no1] == NULL || $contributordet["book_details"]["royalty_choice"][$book_no1] == 1){ #total profit = gross sales- expense $total_profit = $gross_sales_val-$sum; } #royalty check : gross if($contributordet["book_details"]["royalty_choice"][$book_no1] == 2){ #total profit = gross sales- expense $total_profit = $gross_sales_val; } #royalty check : cover price if($contributordet["book_details"]["royalty_choice"][$book_no1] == 3){ #total profit = gross sales- expense $total_profit = $gross_sales_val-$sum; } if(is_float($total_profit) == false){ $total_profit_val= floatval($total_profit); }else{ $total_profit_val = $total_profit; } $total_profit_value = money_format('%+n', $total_profit_val); // echo 'PROFIT THIS QUARTER : '.$total_profit_value.""; echo '"; #contributor's portion of profit value : TOTAL PERCENTAGE TO THE BOOK if(isset($contributordet['book_details']['percentage_Array'][$book_no1])){ $divide_by_val = $contributordet['book_details']['percentage_Array'][$book_no1]; }else{ $divide_by_val = 1; } ##checking the royalty choice of the book #if choice is net : contributor's portion = directly total profit if($contributordet["book_details"]["royalty_choice"][$book_no1] == 1 || $contributordet["book_details"]["royalty_choice"][$book_no1]== NULL || $contributordet["book_details"]["royalty_choice"][$book_no1] == 2){ $contributor_portion = $total_profit*$divide_by_val/100; } #if choice is cover price : "Print Price" * "Creators Portion of Profits") * "Total Quantity Sold this Quarter" if($contributordet["book_details"]["royalty_choice"][$book_no1] == 3){ $contributor_portion = $contributordet["book_details"]["print_price"][$book_no1]*$total_qty*($divide_by_val/100); } if(is_float($contributor_portion) == false){ $contributor_portion_val= floatval($contributor_portion); }else{ $contributor_portion_val = $contributor_portion; } $contributor_portion_value = money_format('%+n', $contributor_portion_val); // echo "
CREATORS' PORTION OF PROFITS ".$divide_by_val."%: ".$contributor_portion_value.""; echo ""; ##calculating the royalty percentage and royalty due #the current quarter $royalty_due = 0; $contributor_amount = 0; foreach($contributordet["user_details"]["percentage"] as $per_key => $percentage){ if($book_no1 == $per_key){ //match the book id foreach($percentage as $manage_payout) #only if the book has more than one contributor assigned else the percentage array totals is enough to show. if($contributordet['book_details']['contri_count'][$book_no1] > 1){ // echo "
CONTRIBUTOR'S ROYALTY PERCENTAGE : ".$manage_payout."%"; echo ""; } #advance // echo "
CURRENT ADVANCE BALANCE : ".money_format('%+n',array_sum($amount_current_quarter[$book_no1])).""; echo ""; #royalty due = totalprofit-advance $royalty_due = $contributor_portion - abs(array_sum($amount_current_quarter[$book_no1])); #checking if the value is float or not. if not convert it to float if(is_float($royalty_due) == false){ $royalty_due= floatval($royalty_due); }elseif($royalty_due == -0){ $royalty_due = 0; } else{ $royalty_due = $royalty_due; } // echo "
TOTAL ROYALTIES DUE : ". money_format('%+n', $royalty_due).""; echo " "; #contributor's amount : royaltydue *($manage pay % / Full percen %) $manage_payout = $manage_payout/100; $full_percentage = $divide_by_val/100; if($full_percentage == 0){ $contributor_amount = $royalty_due*(0); }else{ $contributor_amount = $royalty_due*($manage_payout/$full_percentage); } if(is_float($contributor_amount) == false ){ $contributor_amount= floatval($contributor_amount); }elseif($contributor_amount == -0){ $contributor_amount = 0; } else{ $contributor_amount = $contributor_amount; } // echo "
CONTRIBUTOR'S ROYALTY DUE : ". money_format('%+n', $contributor_amount).""; echo " "; } } #previous quarter balance if(isset($balance_end_q_prev[$book_no1]) && $balance_end_q_prev[$book_no1] != '' && $balance_end_q_prev[$book_no1] !=0 && $balance_end_q_prev[$book_no1] < 0){ // echo "
TOTAL ADVANCE TO CARRY FORWARD : ".money_format('%+n',$balance_end_q_prev[$book_no1]).""; echo ""; } echo '
ROYALTY CHOICE ".$r_choice."
TOTAL QUANTITY SOLD THIS QUARTER ";echo $total_qty."
TOTAL GROSS SALES THIS QUARTER ";echo $gross_sales_value."
TOTAL EXPENSES THIS QUARTER ". $sumvalue."
PROFIT THIS QUARTER '.$total_profit_value."
CREATORS' PORTION OF PROFITS ".$divide_by_val."%: ".$contributor_portion_value."
CONTRIBUTOR'S ROYALTY PERCENTAGE ".$manage_payout."%
CURRENT ADVANCE BALANCE ".money_format('%+n',array_sum($amount_current_quarter[$book_no1]))."
TOTAL ROYALTIES DUE : ". money_format('%+n', $royalty_due)."
CONTRIBUTOR'S ROYALTY DUE ". money_format('%+n', $contributor_amount)."
TOTAL ADVANCE TO CARRY FORWARD ".money_format('%+n',$balance_end_q_prev[$book_no1])."
'; #balance end of current quarter if(isset($balance_end_q_prev[$book_no1])){ if($balance_end_q_prev[$book_no1] > 0){ $prev_qty = 0; } else{ $prev_qty=$balance_end_q_prev[$book_no1]; } }else{ $prev_qty = 0; } $iterations++; } ?>