| 366 | | if ($billingtype == 0){ |
|---|
| 367 | | // PROCESSING FOR MONTHLY |
|---|
| 368 | | // if > last day of the month |
|---|
| 369 | | if ($startday > date("t")) $startday = date("t"); |
|---|
| 370 | | if ($startday <= 0 ) $startday = 1; |
|---|
| 371 | | |
|---|
| 372 | | // Check if the startday is upper that the current day |
|---|
| 373 | | if ($startday > date("j")) $year_month = date('Y-m', strtotime('-1 month')); |
|---|
| 374 | | else $year_month = date('Y-m'); |
|---|
| 375 | | |
|---|
| 376 | | $yearmonth = sprintf("%s-%02d",$year_month,$startday); |
|---|
| 377 | | if ($A2B->config["database"]['dbtype'] == "postgres"){ |
|---|
| 378 | | $UNIX_TIMESTAMP = ""; |
|---|
| 379 | | }else{ |
|---|
| 380 | | $UNIX_TIMESTAMP = "UNIX_TIMESTAMP"; |
|---|
| 381 | | } |
|---|
| 382 | | $CLAUSE_DATE=" $UNIX_TIMESTAMP(date_consumption) >= $UNIX_TIMESTAMP('$yearmonth')"; |
|---|
| 383 | | }else{ |
|---|
| 384 | | // PROCESSING FOR WEEKLY |
|---|
| 385 | | $startday = $startday % 7; |
|---|
| 386 | | $dayofweek = date("w"); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) |
|---|
| 387 | | if ($dayofweek==0) $dayofweek=7; |
|---|
| 388 | | if ($dayofweek < $startday) $dayofweek = $dayofweek + 7; |
|---|
| 389 | | $diffday = $dayofweek - $startday; |
|---|
| 390 | | if ($A2B->config["database"]['dbtype'] == "postgres"){ |
|---|
| 391 | | $CLAUSE_DATE = "date_consumption >= (CURRENT_DATE - interval '$diffday day') "; |
|---|
| 392 | | }else{ |
|---|
| 393 | | $CLAUSE_DATE = "date_consumption >= DATE_SUB(CURRENT_DATE, INTERVAL $diffday DAY) "; |
|---|
| 394 | | } |
|---|
| 395 | | } |
|---|
| 396 | | $QUERY = "SELECT sum(used_secondes) AS used_secondes FROM cc_card_package_offer ". |
|---|
| 397 | | " WHERE $CLAUSE_DATE AND id_cc_card = '".$A2B->id_card."' AND id_cc_package_offer = '$id_cc_package_offer' "; |
|---|
| 398 | | $pack_result = $A2B -> instance_table -> SQLExec ($A2B -> DBHandle, $QUERY); |
|---|
| 399 | | |
|---|
| 400 | | if (is_array($pack_result) && count($pack_result)>0) { |
|---|
| 401 | | $this->freetimetocall_used = $pack_result[0][0]; |
|---|
| 402 | | } else { |
|---|
| 403 | | $this->freetimetocall_used = 0; |
|---|
| 404 | | } |
|---|
| 405 | | |
|---|
| 406 | | $A2B -> write_log ('line:'.__LINE__." - PACK USED TIME : $QUERY ; RESULT -> $this->freetimetocall_used"); |
|---|
| 407 | | if ($this -> debug_st) echo ('line:'.__LINE__." - PACK USED TIME : $QUERY ; RESULT -> $this->freetimetocall_used"); |
|---|
| 408 | | |
|---|
| | 366 | $this -> freetimetocall_used = $A2B -> FT2C_used_seconds($A2B->DBHandle, $A2B->id_card, $id_cc_package_offer, $billingtype, $startday); |
|---|