Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCW-7 created a method for converting the price to two characters and… #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions receipt-web/src/components/ReceiptCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
{{date.format("DD.MM.YYYY HH:mm")}}
</p>
<p class="card-text">
{{receipt.sum}} рублей.
{{totalSum}} рублей.
</p>
<a v-bind:href="href" class="btn btn-primary">Открыть</a>
</div>
</div>
</template>

<script>
import moment from "moment"
import moment from "moment";
import truncated from "./utils/truncated";

export default {
name: 'ReceiptCard',
Expand All @@ -31,7 +32,9 @@
href: function () {
return `/receipt/` + this.receipt.id;
},

totalSum() {
return truncated(this.receipt.sum);
},
cardStyle: function () {
let status = this.receipt.status;
if (status === "FAILED") {
Expand All @@ -45,4 +48,3 @@
}
}
</script>

Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@
<tr v-for="(item, id) in items" v-bind:key="id">
<td>{{item.text}}</td>
<td>{{item.price}} р.</td>
<td>× {{item.amount}}</td>
<td>× {{totalSum(item.amount)}}</td>
</tr>
</tbody>
</table>
</template>
<script>
import truncated from "../../utils/truncated";

export default {
name: 'ReceiptItems',
props: {
items: {
type: Array,
default: () => []
}
},
method: {
totalSum(num) {
return truncated(num);
}
}
}
</script>
5 changes: 3 additions & 2 deletions receipt-web/src/components/pages/ReceiptPage/ReceiptMeta.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</table>
</template>
<script>
import moment from "moment"
import moment from "moment";
import truncated from "../../utils/truncated";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем ../../, если есть @?


export default {
name: "ReceiptMeta",
Expand All @@ -32,7 +33,7 @@
} else if (key === "provider") {
result["Провайдер"] = meta["provider"];
} else if (key === "sum") {
result["Сумма"] = meta["sum"];
result["Сумма"] = truncated(meta["sum"]);
} else if (key === "fn") {
result["Фискальный накопитель"] = meta["fn"];
} else if (key === "fd") {
Expand Down
17 changes: 17 additions & 0 deletions receipt-web/src/components/utils/truncated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function isInteger(num) {
return (num ^ 0) === num;
}

function toStringNumberLength(num) {
const crop = num.toString().split('.');
return crop[1].length;
}

const truncated = num => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

truncate = обрезать, а ты форматируешь
давай переименуем formatSum(number)

и зачем стрелку если можно сделать функцию?

if(isInteger(num) || toStringNumberLength(num) === 1) {
return num.toFixed(2);
}
return Math.trunc((num) * 100) / 100;
}

export default truncated;