Added Call detail CSV to invoice list
This commit is contained in:
@@ -342,7 +342,8 @@ $pagination_entity_name = "Rechnungen";
|
|||||||
<td><?=($invoice->billing_type == "sepa") ? "SEPA" : "Überweisung"?></td>
|
<td><?=($invoice->billing_type == "sepa") ? "SEPA" : "Überweisung"?></td>
|
||||||
<td><?=($invoice->billing_delivery == "email") ? "Email" : "Papier"?></td>
|
<td><?=($invoice->billing_delivery == "email") ? "Email" : "Papier"?></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="<?=self::getUrl("Invoice", "downloadInvoiceCsv", ["id" => $invoice->id])?>" title="CSV-Download"><i class="fas fa-file-csv fa-fw"></i></a>
|
<a href="<?=self::getUrl("Invoice", "downloadInvoiceCsv", ["id" => $invoice->id])?>" title="CSV-Download"><i class="far fa-file-csv fa-fw"></i></a>
|
||||||
|
<a href="<?=self::getUrl("Invoice", "downloadInvoiceVoiceDetails", ["id" => $invoice->id])?>" title="CSV-Download"><i class="far fa-square-phone-flip fa-fw ml-2"></i></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|||||||
@@ -212,6 +212,112 @@ class InvoiceController extends mfBaseController {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function downloadInvoiceVoiceDetailsAction() {
|
||||||
|
$id = $this->request->id;
|
||||||
|
if (!is_numeric($id) || !$id) {
|
||||||
|
$this->layout()->setFlash("Rechnung nicht gefunden", "error");
|
||||||
|
$this->redirect("Invoice");
|
||||||
|
}
|
||||||
|
|
||||||
|
$invoice = new Invoice($id);
|
||||||
|
if (!$invoice->id) {
|
||||||
|
$this->layout()->setFlash("Rechnung nicht gefunden", "error");
|
||||||
|
$this->redirect("Invoice");
|
||||||
|
}
|
||||||
|
|
||||||
|
$csv = "Startzeit;Abgehende Nummer;Zielnummer;Zone;Dauer;Kosten\n";
|
||||||
|
|
||||||
|
$destinations_cache = [];
|
||||||
|
|
||||||
|
foreach($invoice->voicenumbers as $voicenumber) {
|
||||||
|
$start_date = new DateTime($voicenumber->start_date);
|
||||||
|
//$start_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||||
|
$start_date->setTime(0,0,0);
|
||||||
|
$end_date = new DateTime($voicenumber->end_date);
|
||||||
|
//$end_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||||
|
$end_date->setTime(23,59,59);
|
||||||
|
|
||||||
|
foreach(VoiceCallHistoryModel::getVoiceCallHistoryAsEntity([
|
||||||
|
"voice_account" => $voicenumber->voicenumber,
|
||||||
|
"start" => [
|
||||||
|
"from" => $start_date->getTimestamp(),
|
||||||
|
"to" => $end_date->getTimestamp()
|
||||||
|
],
|
||||||
|
"billable" => 1,
|
||||||
|
], null, 0, ["key" => "start", "order" => "ASC"]) as $call) {
|
||||||
|
if(!$call->contract_id) continue;
|
||||||
|
|
||||||
|
//$voiceplan = new Voiceplan($voicenumber->voiceplan_id);
|
||||||
|
$voiceplan = VoiceplanModel::getFirst(["name" => $voicenumber->voiceplan]);
|
||||||
|
if(!$voiceplan) {
|
||||||
|
$this->log->warning(__METHOD__.": Voiceplan not found");
|
||||||
|
};
|
||||||
|
|
||||||
|
$number = $voicenumber->voicenumber;
|
||||||
|
$dest_nummer = $call->destination;
|
||||||
|
if (substr($dest_nummer, 0, 2) == "00") {
|
||||||
|
$dest_nummer = substr($dest_nummer, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($dest_nummer, 0, 1) == "+") {
|
||||||
|
$dest_nummer = substr($dest_nummer, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists($dest_nummer, $destinations_cache)) {
|
||||||
|
$destination = $destinations_cache[$dest_nummer];
|
||||||
|
} else {
|
||||||
|
$destination = $voiceplan->getDestinationByNumber($dest_nummer);
|
||||||
|
if (!$destination) {
|
||||||
|
die("Destination für Zielrufnummer " . $call->destination . " nicht gefunden");
|
||||||
|
}
|
||||||
|
$destinations_cache[$dest_nummer] = $destination;
|
||||||
|
}
|
||||||
|
//var_dump($destination);
|
||||||
|
|
||||||
|
$zone = $destination->voiceplanzone;
|
||||||
|
|
||||||
|
if (!$zone) {
|
||||||
|
die("Keine Zone für Destination " . $dest_nummer . " gefunden");
|
||||||
|
}
|
||||||
|
|
||||||
|
//var_dump($zone);exit;
|
||||||
|
|
||||||
|
// inc_first - first minimumm duration to bill
|
||||||
|
// inc - subsequent minimum duration to bill
|
||||||
|
$inc_first = $zone->increment_first;
|
||||||
|
$inc = $zone->increment;
|
||||||
|
|
||||||
|
$billable_duration = $call->duration;
|
||||||
|
if ($billable_duration <= 0) continue;
|
||||||
|
|
||||||
|
// calculate price of first duration unit
|
||||||
|
// then subtract first minimum duration from duration
|
||||||
|
$sec_price = $zone->price / 60;
|
||||||
|
$call_price = $inc_first * $sec_price;
|
||||||
|
$billable_duration -= $inc_first;
|
||||||
|
|
||||||
|
// calculate price of remaining duration and make sure to bill in full duration units
|
||||||
|
if ($billable_duration > 0) {
|
||||||
|
$multi = ceil($billable_duration / $inc);
|
||||||
|
$call_price += ($multi * $inc) * $sec_price;
|
||||||
|
}
|
||||||
|
|
||||||
|
$csv .= '"'.$call->start.'";';
|
||||||
|
$csv .= '"'.$call->source.'"; ';
|
||||||
|
$csv .= '"'.$call->destination.'"; ';
|
||||||
|
$csv .= '"'.$zone->name.'"; ';
|
||||||
|
$csv .= $call->duration.'; ';
|
||||||
|
$csv .= '"'.str_replace(".",",", $call_price).'"';
|
||||||
|
$csv .= "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
header("Content-type: text/csv; charset=utf-8");
|
||||||
|
header('Content-disposition: attachment; filename="'.$invoice->invoice_number.'-egn.csv"');
|
||||||
|
echo $csv;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
protected function createJob() {
|
protected function createJob() {
|
||||||
$r = $this->request;
|
$r = $this->request;
|
||||||
|
|||||||
Reference in New Issue
Block a user