コード例 #1
0
 public static function apiQuery()
 {
     $query = self::query();
     if (!Auth::user()->isAdmin()) {
         $query->where(PayeeCompany::table() . '.company_id', '=', Auth::user()["company_id"]);
     }
     $query->join(User::table() . " as user", 'user.id', '=', 'user_id');
     return $query;
 }
コード例 #2
0
 public function savePayees($rpf)
 {
     //        $payments = RoyaltyPayment::groupedByPayeeCode($rpf->id)->get();
     //        foreach ($payments as $payment) {
     //            $user = User::where('code', '=', $payment->payee_code)->first();
     //            if ($user == null) {
     //                $user = User::create(["name"       => $payment->payee_name,
     //                                      "deleted_at" => null,
     //                                      "email"      => null,
     //                                      "code"       => $payment->payee_code,
     //                                      "company_id" => $rpf->company_id,
     //                                      "password"   => $payment->payee_code,
     //                                      "type"       => "payee"]);
     //                PayeeCompany::create(["user_id" => $user->id, "code" => $user->code, "company_id" => $rpf->company_id]);
     //            } else {
     //                if (PayeeCompany::findByUserAndCompany($user->id, $rpf->company_id) == null)
     //                    PayeeCompany::create(["user_id" => $user->id, "code" => $user->code, "company_id" => $rpf->company_id]);
     //            }
     //        }
     DB::connection()->getpdo()->exec('INSERT IGNORE INTO ' . User::table() . '(`name`, `deleted_at`, `email`, `code`, `company_id`, `password`, `type`)
          SELECT `payee_name`, NULL, NULL, `payee_code`, ' . $rpf->company_id . ', ENCRYPT(`payee_code`), \'payee\'
           FROM ' . RoyaltyPayment::table() . '
           WHERE `royalty_payment_file_id` = ' . $rpf->id . ' AND `payee_payment_id` IS NULL
           GROUP BY `payee_code` ORDER BY `payee_code`');
     DB::connection()->getpdo()->exec('INSERT IGNORE INTO ' . PayeeCompany::table() . '(`user_id`, `code`, `company_id`)
          SELECT u.id, `payee_code`, ' . $rpf->company_id . '
           FROM ' . RoyaltyPayment::table() . ' as rp
           LEFT JOIN ' . User::table() . ' as u on rp.payee_code = u.code
           WHERE `royalty_payment_file_id` = ' . $rpf->id . ' AND `payee_payment_id` IS NULL
           GROUP BY `payee_code` ORDER BY `payee_code`');
 }
コード例 #3
0
 public function testMultipleCompaniesForTheSamePayees()
 {
     $this->resetEvents();
     $path = $this->copyFileToTemp($this->fileName());
     $s = $this->service();
     $companyId1 = rand(1000, 1000000);
     $companyId2 = rand(1000, 1000000);
     $fileDetails = ["year" => 2015, "month" => 7];
     $rpf = $s->process($path, $companyId1, $fileDetails);
     $this->assertTrue($rpf->status == RoyaltyPaymentFile::STATUS_PAYMENTS_PROCESSED);
     $path = $this->copyFileToTemp($this->fileName());
     $rpf = $s->process($path, $companyId2, $fileDetails);
     $this->assertTrue($rpf->status == RoyaltyPaymentFile::STATUS_PAYMENTS_PROCESSED);
     $payees = User::all();
     $this->assertTrue(count($payees) == 2);
     $payee1 = $payees[0];
     $this->assertTrue($payee1->id == 1);
     $this->assertTrue($payee1->company_id == $companyId1);
     $this->assertTrue($payee1->type == "payee");
     $this->assertTrue($payee1->email == null);
     $this->assertTrue($payee1->code == "1175");
     $this->assertTrue($payee1->name == "Studio 51");
     $payee2 = $payees[1];
     $this->assertTrue($payee2->id == 2);
     $this->assertTrue($payee2->company_id == $companyId1);
     $this->assertTrue($payee2->type == "payee");
     $this->assertTrue($payee2->email == null);
     $this->assertTrue($payee2->code == "1379");
     $this->assertTrue($payee2->name == "Pop Virus (PACIFICA)");
     $payeeCompany = PayeeCompany::all();
     $this->assertTrue(count($payeeCompany) == 4);
     $this->assertTrue($payeeCompany[0]->user_id == 1);
     $this->assertTrue($payeeCompany[0]->code == 1175);
     $this->assertTrue($payeeCompany[0]->company_id == $companyId1);
     $this->assertTrue($payeeCompany[1]->user_id == 2);
     $this->assertTrue($payeeCompany[1]->code == 1379);
     $this->assertTrue($payeeCompany[1]->company_id == $companyId1);
     $this->assertTrue($payeeCompany[2]->user_id == 1);
     $this->assertTrue($payeeCompany[2]->code == 1175);
     $this->assertTrue($payeeCompany[2]->company_id == $companyId2);
     $this->assertTrue($payeeCompany[3]->user_id == 2);
     $this->assertTrue($payeeCompany[3]->code == 1379);
     $this->assertTrue($payeeCompany[3]->company_id == $companyId2);
     $path = $this->copyFileToTemp($this->fileName());
     $rpf = $s->process($path, $companyId2, $fileDetails);
     $this->assertTrue($rpf->status == RoyaltyPaymentFile::STATUS_PAYMENTS_PROCESSED);
     $payeeCompany = PayeeCompany::all();
     $this->assertTrue(count($payeeCompany) == 4);
     $this->assertTrue($payeeCompany[0]->user_id == 1);
     $this->assertTrue($payeeCompany[0]->code == 1175);
     $this->assertTrue($payeeCompany[0]->company_id == $companyId1);
     $this->assertTrue($payeeCompany[1]->user_id == 2);
     $this->assertTrue($payeeCompany[1]->code == 1379);
     $this->assertTrue($payeeCompany[1]->company_id == $companyId1);
     $this->assertTrue($payeeCompany[2]->user_id == 1);
     $this->assertTrue($payeeCompany[2]->code == 1175);
     $this->assertTrue($payeeCompany[2]->company_id == $companyId2);
     $this->assertTrue($payeeCompany[3]->user_id == 2);
     $this->assertTrue($payeeCompany[3]->code == 1379);
     $this->assertTrue($payeeCompany[3]->company_id == $companyId2);
     $this->resetEvents();
 }
コード例 #4
0
ファイル: User.php プロジェクト: alternativex/Backend-app
 public static function apiPayeesCounts()
 {
     return ["new_payees" => PayeeCompany::payeesWithoutEmail()->count(), "all_payees" => PayeeCompany::payeesWithEmail()->count(), "unpaid_statements" => PayeePayment::unpaid()->count(), "paid_statements" => PayeePayment::paid()->count()];
 }