Example #1
0
    if (isset($_POST['vahvistamattomat_edellisesta_kk'])) {
        $criteria = new CDbCriteria();
        $criteria->condition = " \n\t\t\tmyyja_id='" . $_POST['user_id'] . "' \n\t\t\tAND vuosi='" . (int) date("Y", strtotime($_POST['vuosi'] . '-' . $_POST['kuukausi'] . ' -1 month')) . "'\n\t\t\tAND kuukausi='" . (int) date("n", strtotime($_POST['vuosi'] . '-' . $_POST['kuukausi'] . ' -1 month')) . "'\n\t\t";
        $prE = Provisiot::model()->find($criteria);
        if (isset($prE->id) and !empty($prE->maksetut_kuitista)) {
            $vahvistammatomat_edellisesta_kk = json_decode($_POST['vahvistamattomat_edellisesta_kk'], true);
            $maksetut_kuitista = json_decode($prE->maksetut_kuitista, true);
            $newArray = array();
            foreach ($vahvistammatomat_edellisesta_kk as $k => $v) {
                $newArray[$k] = $v;
            }
            foreach ($maksetut_kuitista as $k => $v) {
                $newArray[$k] = $v;
            }
            //print_r($newArray);
            Provisiot::model()->updateBypk($prE->id, array('maksetut_kuitista' => json_encode($newArray)));
        }
    }
}
echo '<h2>Tilityslista</h2>';
$months = array('1' => 'Tammikuu', '2' => 'Helmikuu', '3' => 'Maaliskuu', '4' => 'Huhtikuu', '5' => 'Toukokuu', '6' => 'Kesäkuu', '7' => 'Heinäkuu', '8' => 'Elokuu', '9' => 'Syyskuu', '10' => 'Lokakuu', '11' => 'Marraskuu', '12' => 'Joulukuu');
$thisYear = !empty($_GET['y']) ? (int) $_GET['y'] : date('Y');
$thisMonth = !empty($_GET['m']) ? (int) $_GET['m'] : date('n');
echo '<div class="row">
	<div class="col-sm-3">';
echo '<p>
	<h4><a href="?y=' . ($thisYear - 1) . '">', $thisYear - 1, '</a> - 
	<a href="?y=', $thisYear + 1, '">', $thisYear + 1, '</a>
	</h4></p>';
for ($month = 1; $month <= 12; $month++) {
    $cl = 'btn btn-block btn-sm btn-warning';
Example #2
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Provisiot the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Provisiot::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #3
0
 echo '<p>Vahvistamattomat provisiot: ' . number_format(array_sum($vahvistamattomat), 2, ',', ' ') . ' &euro;</p>';
 echo '<p>' . $masmattomatNimike . ': ' . number_format(array_sum($maksamattomat), 2, ',', ' ') . ' &euro;</p>';
 echo '<p>Tämän kuukauden myynneistä maksettava provisio: ' . number_format(array_sum($maksetut), 2, ',', ' ') . ' &euro;</p>';
 // vahvistomattomat edellinen kk
 $criteria = new CDbCriteria();
 $criteria->order = "  id DESC ";
 $criteria->condition = " myyja_id='" . $id . "' AND vuosi='" . (int) date("Y", strtotime($thisYear . '-' . $thisMonth . ' -1 month')) . "' AND kuukausi='" . (int) date("n", strtotime($thisYear . '-' . $thisMonth . ' -1 month')) . "' ";
 $prE = Provisiot::model()->find($criteria);
 $edellinenkkVahv = 0;
 if (isset($prE->id)) {
     $edellinenkkVahv = $prE->vahvistamattomat;
 }
 $criteria = new CDbCriteria();
 $criteria->order = "  id DESC ";
 $criteria->condition = " myyja_id='" . $id . "' AND vuosi='" . $thisYear . "' AND kuukausi='" . (int) $thisMonth . "' ";
 $pr = Provisiot::model()->find($criteria);
 $edellinen_maksamattomat = 0;
 if (isset($pr->id)) {
     if (array_sum($maksamattomatE) > 0) {
         $edellinen_maksamattomat = array_sum($maksamattomatE);
         echo '<b>Edelliseltä kohdekuukaudelta maksettava provisio:</b>';
         echo '<p>' . $months[date("n", strtotime($thisYear . '-' . $thisMonth . ' -1 month'))] . ': ' . number_format(array_sum($maksamattomatE), 2, ',', ' ') . ' &euro;</p>';
     } else {
         echo '<b>Edelliseltä kohdekuukaudelta ei maksettavaa</b>';
     }
     $yht = $edellinen_maksamattomat + array_sum($maksetut);
     $alv = 0;
     $alvT = '';
     if ($alv_velvollinen == 'Kyllä') {
         $alv = $yht * 0.24;
         $alvT = '<p>ALV: ' . number_format($alv, 2, ',', ' ') . '&euro;</p>';
Example #4
0
    protected function allProvisio($id, $thisYear, $thisMonth)
    {
        $profile = Profile::model()->findByPk($id);
        $alv_velvollinen = $profile->alv_velvollinen == 1 ? 'Kyllä' : 'Ei';
        $maksetut = array();
        $criteria = new CDbCriteria();
        $criteria->condition = " \n\t\tmyyja_id='" . $id . "' \n\t\tAND vuosi='" . $thisYear . "'\n\t\tAND kuukausi='" . $thisMonth . "'\n\t";
        $pr = Provisiot::model()->find($criteria);
        if (isset($pr->id)) {
            $m = json_decode($pr->maksettu_id, true);
        }
        if (isset($m) and is_array($m)) {
            $maksetut = $m;
        }
        $u = User::model()->findAll(" myyjaID='" . $id . "' ");
        $vahvistamattomat = array();
        $maksamattomat = array();
        foreach ($u as $data) {
            $o = $this->ordersDataForProvision($data->id, $thisYear, $thisMonth);
            foreach ($o as $ord) {
                $v = date("Y-m-d", strtotime($ord->maksettu_pvm . " +14 day"));
                $ord->hinta = $this->hintaLaske($ord, 0.3);
                if ($v > date("Y-m-d")) {
                    $vahvistamattomat[$ord->id] = $ord->hinta;
                } elseif ($v <= date("Y-m-d") and !isset($maksetut[$ord->id])) {
                    $maksamattomat[$ord->id] = $ord->hinta;
                }
            }
        }
        // Muut myyjat
        $u = User::model()->findAll(" paa_myyja='" . $id . "' ");
        foreach ($u as $uu) {
            if (isset($uu->id)) {
                $criteria = new CDbCriteria();
                $criteria->order = "  id DESC ";
                $criteria->condition = " myyjaID='" . $uu->id . "' ";
                $u = User::model()->findAll($criteria);
                foreach ($u as $data) {
                    $o = $this->ordersDataForProvision($data->id, $thisYear, $thisMonth);
                    foreach ($o as $ord) {
                        $v = date("Y-m-d", strtotime($ord->maksettu_pvm . " +14 day"));
                        $ord->hinta = $this->hintaLaske($ord, 0.1);
                        if ($v > date("Y-m-d")) {
                            $vahvistamattomat[$ord->id] = $ord->hinta;
                        } elseif ($v <= date("Y-m-d") and !isset($maksetut[$ord->id])) {
                            $maksamattomat[$ord->id] = $ord->hinta;
                        }
                    }
                }
            }
        }
        // Edellinen maksamattomat
        $criteria = new CDbCriteria();
        $criteria->condition = " \n\t\tmyyja_id='" . $id . "' \n\t\tAND vuosi='" . date("Y", strtotime($thisYear . '-' . $thisMonth . ' -1 month')) . "'\n\t\tAND kuukausi='" . (int) date("n", strtotime($thisYear . '-' . $thisMonth . ' -1 month')) . "'\n\n\t";
        $prEE = Provisiot::model()->find($criteria);
        if (isset($prEE->id)) {
            $m = json_decode($prEE->maksettu_id, true);
        }
        if (isset($m) and is_array($m)) {
            $maksetutE = $m;
        }
        $u = User::model()->findAll(" myyjaID='" . $id . "' ");
        $maksamattomatE = array();
        foreach ($u as $data) {
            $o = $this->ordersDataForProvisionEdellinen($data->id, $thisYear, $thisMonth);
            foreach ($o as $ord) {
                $v = date("Y-m-d", strtotime($ord->maksettu_pvm . " +14 day"));
                $ord->hinta = $this->hintaLaske($ord, 0.3);
                if ($v > date("Y-m-d")) {
                } elseif ($v <= date("Y-m-d") and !isset($maksetutE[$ord->id])) {
                    $maksamattomatE[$ord->id] = $ord->hinta;
                }
            }
        }
        // Muut myyjat
        $u = User::model()->findAll(" paa_myyja='" . $id . "' ");
        foreach ($u as $uu) {
            if (isset($uu->id)) {
                $p = Profile::model()->findByPk($uu->id);
                $criteria = new CDbCriteria();
                $criteria->order = "  id DESC ";
                $criteria->condition = " myyjaID='" . $uu->id . "' ";
                $u = User::model()->findAll($criteria);
                foreach ($u as $data) {
                    $o = $this->ordersDataForProvisionEdellinen($data->id, $thisYear, $thisMonth);
                    foreach ($o as $ord) {
                        $v = date("Y-m-d", strtotime($ord->maksettu_pvm . " +14 day"));
                        $ord->hinta = $this->hintaLaske($ord, 0.1);
                        if ($v > date("Y-m-d")) {
                        } elseif ($v <= date("Y-m-d") and !isset($maksetutE[$ord->id])) {
                            $maksamattomatE[$ord->id] = $ord->hinta;
                        }
                    }
                }
            }
        }
        // vahvistomattomat edellinen kk
        $criteria = new CDbCriteria();
        $criteria->order = "  id DESC ";
        $criteria->condition = " myyja_id='" . $id . "' AND vuosi='" . (int) date("Y", strtotime($thisYear . '-' . $thisMonth . ' -1 month')) . "' AND kuukausi='" . (int) date("n", strtotime($thisYear . '-' . $thisMonth . ' -1 month')) . "' ";
        $prE = Provisiot::model()->find($criteria);
        $edellinenkkVahv = 0;
        if (isset($prE->id)) {
            $edellinenkkVahv = $prE->vahvistamattomat;
        }
        $criteria = new CDbCriteria();
        $criteria->order = "  id DESC ";
        $criteria->condition = " myyja_id='" . $id . "' AND vuosi='" . $thisYear . "' AND kuukausi='" . (int) $thisMonth . "' ";
        $pr = Provisiot::model()->find($criteria);
        $edellinen_maksamattomat = 0;
        if (isset($pr->id)) {
            if (array_sum($maksamattomatE) > 0) {
                $edellinen_maksamattomat = array_sum($maksamattomatE);
            }
            $yht = $edellinen_maksamattomat + array_sum($maksetut);
            $alv = 0;
            $alvT = '';
            $maksettava_prov = 0;
            if ($alv_velvollinen == 'Kyllä') {
                $alv = $yht * 0.24;
                $alvT = 'ALV: ' . number_format($alv, 2, ',', ' ') . '&euro;';
            }
            $maksettava_prov = number_format($yht + $alv, 2, ',', ' ') . ' &euro;';
        }
        if (isset($pr->id) and $pr->kuitattu == 0) {
            $vahvistamattomat_edellisesta_kk = '';
            if (isset($prE->vahvistamattomat_id) and !empty($prE->vahvistamattomat_id)) {
                $vahvistamattomat_edellisesta_kk = '<textarea name="vahvistamattomat_edellisesta_kk" style="display:none">' . $prE->vahvistamattomat_id . '</textarea>';
            }
            $painike = '
			<form action="#" method="POST">
			<input type="hidden" name="newprovisio">
			<input type="hidden" name="user_id" value="' . $id . '">
			<input type="hidden" name="vuosi" value="' . $thisYear . '">
			<input type="hidden" name="kuukausi" value="' . $thisMonth . '">
			<textarea name="maksetut_kuitista" style="display:none">' . json_encode($maksetut) . '</textarea>
			' . $vahvistamattomat_edellisesta_kk;
            if ($maksettava_prov == 0) {
                $teksti1 = 'Kuittaa kuukausi';
            } else {
                $teksti1 = 'Kuittaa maksetuksi';
            }
            if (isset($prE->id) and $prE->kuitattu == 0) {
                $painike .= 'Edellinen kuukausi on kuittaamatta.';
            } else {
                $painike .= '<input type="submit" class="kuitta btn btn-success btn-sm" value="' . $teksti1 . '">';
            }
            $painike .= '</form>';
        } elseif (isset($pr->id) and $pr->kuitattu == 1) {
            $painike = 'Provisiot on kuitattu maksetuksi';
        }
        $linkki = '';
        if (date("Ym") > date("Ym", strtotime($thisYear . '-' . $thisMonth)) and isset($pr->id)) {
            $edellinen_maksamattomat = '';
            if (array_sum($maksamattomatE) > 0) {
                $edellinen_maksamattomat = '&em=' . array_sum($maksamattomatE);
            }
            $linkki = '<a href="tilitysraportti?myyja_id=' . $id . '&y=' . $thisYear . '&m=' . date("m", strtotime($thisYear . '-' . $thisMonth)) . $edellinen_maksamattomat . '">linkki</a>';
        }
        $return = array($profile->firstname, $profile->lastname, $profile->pankkitilinumero, $alv_velvollinen, $profile->y_tunnus, $maksettava_prov, $alvT, $linkki, $painike);
        return $return;
    }