<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>hiro-is-idのブログ</title>
<link>https://ameblo.jp/hiro-is-id/</link>
<atom:link href="https://rssblog.ameba.jp/hiro-is-id/rss20.xml" rel="self" type="application/rss+xml" />
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com" />
<description>ブログの説明を入力します。</description>
<language>ja</language>
<item>
<title>ReceiptsLogic</title>
<description>
<![CDATA[ <p>&lt;?php</p><p>namespace App\Model\Logic;</p><p>&nbsp;</p><p>use App\Common\Constants as C;</p><p>use App\Common\Functions as F;</p><p><br>&nbsp;</p><p>//TODO:関数の並べ替え。関数の概要</p><p>class ReceiptsLogic {</p><p><br>&nbsp;</p><p>&nbsp; &nbsp; // const COLUMNS = ['m_accounts_physical_name', 'price', 'tax', 'rate', 'summary'];</p><p>&nbsp;</p><p>&nbsp; &nbsp; public static function getKeyValueArr(object $pMasterObj): array {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $selectedMasterObj = $pMasterObj-&gt;select([C::ID, C::LOGICAL_NAME]);</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $keyValueArr = array();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // $keyValueArr = ['' =&gt; C::HYPHEN];</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; foreach ($selectedMasterObj as $value) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $keyValueArr[$value[C::ID]] = $value[C::LOGICAL_NAME];</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return $keyValueArr;</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; public static function getTaxTypeArr(): array {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return [C::S0 =&gt; '非課税', C::S1 =&gt; '内税', C::S2 =&gt; '外税'];</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; static function getRateArr(): array {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return [C::S0 =&gt; C::S0, C::S8 =&gt; C::S8, C::S1 . C::S0 =&gt; C::S1 . C::S0];</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; static function getNumOfRows(): int {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return C::NUM_OF_ROWS;</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; public static function getFormat(): string {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return F::getFormat(C::NUM_OF_ROWS);</p><p>&nbsp; &nbsp; }</p><p><br>&nbsp;</p><p>&nbsp; &nbsp; public static function getYearArr(): array {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $thisYear = date('y');</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $lastYear = strval(intval($thisYear) - C::I1);</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return [$thisYear =&gt; $thisYear, $lastYear =&gt; $lastYear];</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; public static function getMonthArr(): array {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return self::getNumberArr(12);</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; public static function getThisMonth(): string {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return sprintf('%02d', date('m'));</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; public static function getDayArr(): array {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return self::getNumberArr(31);</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; public static function getThisDay(): string {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return sprintf('%02d', date('d'));//TODO:'d'の定数化</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; public static function validateData(array $pData): array {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return self::priValidateData($pData);</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; // 以下privateメソッド ----------------------------------------</p><p>&nbsp;</p><p>&nbsp; &nbsp; private static function getNumberArr(int $pLastNumber): array {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $numberArr = array();</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; for ($i = C::I1; $i &lt;= $pLastNumber; $i++) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $formatted = sprintf(F::getFormat($pLastNumber), $i);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $numberArr[$formatted] = $formatted;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return $numberArr;</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; private static function priValidateData(array $pData): array {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $errorMessage = null;</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (!checkdate(intval($pData['month']), intval($pData['day']), intval('20' . $pData['year']))) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 日付に不備がある場合</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $errorMessage = '日付が不正';</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (2 === intval($pData['tax_type']) &amp;&amp; intval($pData['receipt_total']) &lt;= C::I0) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // レシート合計が入力されていない場合</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $errorMessage = F::apndMsg_($errorMessage, 'レシート合計' . C::GA . C::MI . C::NYURYOKU);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $validatedLine = self::validateRow($pData);</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (isset($validatedLine[C::ERROR_MESSAGE])) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 明細行に不備がある場合</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $errorMessage = F::apndMsg_($errorMessage, $validatedLine[C::ERROR_MESSAGE]);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $validatedLine[C::ERROR_MESSAGE] = $errorMessage;</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return $validatedLine;</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; //TODO:戻り値の型の変更検討</p><p>&nbsp; &nbsp; /**</p><p>&nbsp; &nbsp; &nbsp;* 「レシート追加」ページの明細行の各項目が入力、または、選択されているか否かをチェックする</p><p>&nbsp; &nbsp; &nbsp;*</p><p>&nbsp; &nbsp; &nbsp;* @param $pRequest</p><p>&nbsp; &nbsp; &nbsp;* @return [エラーメッセージ, チェックをパスした行]の配列(チェックをパスした行が二次元配列のため、戻り値は三次元配列)</p><p>&nbsp; &nbsp; &nbsp;*/</p><p>&nbsp; &nbsp; private static function validateRow(array $pData): array {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $priceIArr = array(); &nbsp; &nbsp; &nbsp; // 価格</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $priceRArr = array();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $taxRArr = array(); &nbsp; &nbsp; &nbsp; &nbsp; // 税額</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $taxIArr = array(); &nbsp; &nbsp; &nbsp; &nbsp; // 税額</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $empRowCtrIArr = array(); &nbsp; // 空行カウンタ</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $rowMsgArr = array(); &nbsp; &nbsp; &nbsp; // エラーメッセージ</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $rateRArr = array();</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $totalPriceR = '0.00';</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $totalTaxX100I = C::S0;</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $sum0I = C::S0;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $sum8I = C::S0;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $sum10I = C::S0;</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; for ($i = C::I0; $i &lt; C::NUM_OF_ROWS; $i++) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $formatted = sprintf(self::getFormat(), $i);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $colMsgArr = array();</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 勘定科目</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (empty($pData[C::M_ACCOUNTS_ID_ . $formatted])) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $colMsgArr[0] = C::KANJOKAMOKU . C::GA . C::MI . C::SENTAKU;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 価格</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $priceI = $pData[C::PRICE_ . $formatted];</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (! is_numeric($priceI)) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $colMsgArr[1] = C::KAKAKU . C::GA . C::MI . C::NYURYOKU;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // } else {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; &nbsp; $priceIArr[] = intval($priceI);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; &nbsp; $priceRArr[] = floatval($priceI);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 税率</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $rateI = $pData[C::RATE_ . $formatted];</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (! is_numeric($rateI)) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $colMsgArr[2] = C::ZEIRITSU . C::GA . C::MI . C::SENTAKU;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 備考</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $isSumEmpty = C::I0 === strlen(strval($pData[C::SUMMARY_ . $formatted]));</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $errCnt = count($colMsgArr);</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (3 === $errCnt &amp;&amp; $isSumEmpty) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // (外税かつ科目価格税率が未選択未入力、または、外税以外かつ科目価格税額税率が未選択未入力)、かつ、備考が未入力の場合</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $empRowCtrIArr[] = 1;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } elseif (0 &lt; $errCnt) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 現在の明細行のいずれかの列に不備がない場合</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $rowMsgArr[] = C::NUMERO_SIGN . strval($i + C::I1) . 'の' . implode(C::TOTEN, $colMsgArr);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else /*if (is_numeric($priceI) &amp;&amp; is_numeric($rateI))*/ {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 現在の明細行に不備がない場合</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $totalPriceR = bcadd($totalPriceR, $priceI, 2);</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (C::I0 === strcmp(C::S2, $pData['tax_type'])) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 消費税が外税の場合</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $taxX100I = bcmul($priceI, $rateI);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $totalTaxX100I = bcadd($totalTaxX100I, $taxX100I);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $taxRArr[] = bcdiv($taxX100I, '100', 2);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $taxIArr[$formatted] = bcdiv($taxX100I, '100');</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch ($rateI) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case '0':</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $sum0I = bcadd($sum0I, $priceI);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case '8':</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $sum8I = bcadd($sum8I, $priceI);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case '10':</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $sum10I = bcadd($sum10I, $priceI);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $totalTaxR = null;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $errorMessage = null;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (C::NUM_OF_ROWS === count($empRowCtrIArr)) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 行数と空行数が同じ(明細が一行も入力されていない)場合、その旨をエラーメッセージに設定する</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $errorMessage = '明細が一行も' . C::NYURYOKU . 'されていない';//TODO:定数化検討</p><p>&nbsp; &nbsp; &nbsp; &nbsp; } elseif (C::I0 &lt; count($rowMsgArr)) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $errorMessage = implode('&lt;br&gt;', $rowMsgArr);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; } elseif (C::I0 === strcmp(C::S2, $pData['tax_type'])) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 消費税が外税の場合</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $totalTaxR = bcdiv($totalTaxX100I, '100', 2);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $totalPriceIncludingTaxR = bcadd($totalPriceR, $totalTaxR, 2);</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $diffR = bcsub($pData['receipt_total'], $totalPriceIncludingTaxR, 2);</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (C::I0 !== strcmp('0.00', $diffR)) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $errorMessage = '価格合計と税額合計の和がレシート合計と等しくない';</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; //</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return [</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; C::ERROR_MESSAGE =&gt; $errorMessage,</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'totalPrice' =&gt; F::getIntPart($totalPriceR),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'totalTax' =&gt; F::getIntPart($totalTaxR),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'taxArr' =&gt; $taxIArr</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ];</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; private static function hogeMethod(array $pTaxRArr) {</p><p>&nbsp;</p><p>&nbsp; &nbsp; }</p><p><br><br><br>&nbsp;</p><p>}</p><p>&nbsp;</p>
]]>
</description>
<link>https://ameblo.jp/hiro-is-id/entry-12962320196.html</link>
<pubDate>Wed, 08 Apr 2026 06:24:44 +0900</pubDate>
</item>
</channel>
</rss>
