تقرير الإيرادات الشهري بالبريد
في أول كل شهر، تصلك إيرادات Stripe للشهر الماضي مقارنة بالشهر الذي قبله.
كيف تعمل
المشغّل: جدول زمني — أول كل شهر الساعة 8:00
- اجلب المدفوعات الأخيرة من Stripe.
- اجمع المدفوعات الناجحة للشهر الماضي والشهر الذي قبله.
- أرسل لنفسك الإجماليين ونسبة النمو.
المخطط
مشغّل تطبيق كود
الكود
كود JavaScript المستخدم في خطوات Code، وهو مضمَّن بالفعل في القالب بالأسفل.
// Compares last month's successful charges with the month before.
const now = new Date();
const startOf = (monthsAgo) => new Date(now.getFullYear(), now.getMonth() - monthsAgo, 1).getTime() / 1000;
const lastStart = startOf(1);
const thisStart = startOf(0);
const prevStart = startOf(2);
const charges = $input.all().map((item) => item.json).filter((c) => c.status === "succeeded" && c.paid);
const total = (from, to) =>
charges.filter((c) => c.created >= from && c.created < to).reduce((sum, c) => sum + c.amount / 100, 0);
const last = total(lastStart, thisStart);
const prev = total(prevStart, lastStart);
const growth = prev ? Math.round(((last - prev) / prev) * 100) : 0;
const month = new Date(lastStart * 1000).toLocaleString("en-US", { month: "long", year: "numeric" });
return [{
json: {
subject: `Revenue report — ${month}`,
body:
`${month}: ${last.toFixed(2)}\n` +
`Month before: ${prev.toFixed(2)}\n` +
`Growth: ${growth >= 0 ? "▲" : "▼"} ${Math.abs(growth)}%`,
},
}];ابنِها بأداتك
اختر أداتك — نفس الأتمتة، خطوة بخطوة.
انسخه والصقه مباشرة في مساحة عمل n8n (Ctrl+V)، أو حمّله واستخدم Import from File. بعد ذلك اربط حساباتك واستبدل كل قيمة تبدأ بـ YOUR_.
عرض الكود (131 سطر)
{
"name": "تقرير الإيرادات الشهري بالبريد (Flowngn)",
"nodes": [
{
"parameters": {
"content": "## تقرير الإيرادات الشهري بالبريد\nفي أول كل شهر، تصلك إيرادات Stripe للشهر الماضي مقارنة بالشهر الذي قبله.\n\n**Setup**\n1. Open each node and connect your own credentials.\n2. Replace every YOUR_… placeholder.\n3. Test once, then activate.\n\nFree template from Flowngn",
"height": 260,
"width": 340
},
"id": "2f780998-9838-445d-a923-1c16b94b02ed",
"name": "Setup notes",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
-420,
-60
]
},
{
"parameters": {
"rule": {
"interval": [
{
"field": "months",
"triggerAtDayOfMonth": 1,
"triggerAtHour": 8
}
]
}
},
"id": "2f780998-9838-445d-a923-1c16b94b02ed",
"name": "1st of month 8:00",
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.2,
"position": [
0,
0
]
},
{
"parameters": {
"resource": "charge",
"operation": "getAll",
"returnAll": true
},
"id": "2f780998-9838-445d-a923-1c16b94b02ed",
"name": "Get charges",
"type": "n8n-nodes-base.stripe",
"typeVersion": 1,
"position": [
300,
0
]
},
{
"parameters": {
"jsCode": "// Compares last month's successful charges with the month before.\nconst now = new Date();\nconst startOf = (monthsAgo) => new Date(now.getFullYear(), now.getMonth() - monthsAgo, 1).getTime() / 1000;\n\nconst lastStart = startOf(1);\nconst thisStart = startOf(0);\nconst prevStart = startOf(2);\n\nconst charges = $input.all().map((item) => item.json).filter((c) => c.status === \"succeeded\" && c.paid);\nconst total = (from, to) =>\n charges.filter((c) => c.created >= from && c.created < to).reduce((sum, c) => sum + c.amount / 100, 0);\n\nconst last = total(lastStart, thisStart);\nconst prev = total(prevStart, lastStart);\nconst growth = prev ? Math.round(((last - prev) / prev) * 100) : 0;\nconst month = new Date(lastStart * 1000).toLocaleString(\"en-US\", { month: \"long\", year: \"numeric\" });\n\nreturn [{\n json: {\n subject: `Revenue report — ${month}`,\n body:\n `${month}: ${last.toFixed(2)}\\n` +\n `Month before: ${prev.toFixed(2)}\\n` +\n `Growth: ${growth >= 0 ? \"▲\" : \"▼\"} ${Math.abs(growth)}%`,\n },\n}];"
},
"id": "2f780998-9838-445d-a923-1c16b94b02ed",
"name": "Compare months",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
600,
0
]
},
{
"parameters": {
"sendTo": "you@yourcompany.com",
"subject": "={{ $json.subject }}",
"emailType": "text",
"message": "={{ $json.body }}",
"options": {
"appendAttribution": false
}
},
"id": "2f780998-9838-445d-a923-1c16b94b02ed",
"name": "Email report",
"type": "n8n-nodes-base.gmail",
"typeVersion": 2.1,
"position": [
900,
0
]
}
],
"connections": {
"1st of month 8:00": {
"main": [
[
{
"node": "Get charges",
"type": "main",
"index": 0
}
]
]
},
"Get charges": {
"main": [
[
{
"node": "Compare months",
"type": "main",
"index": 0
}
]
]
},
"Compare months": {
"main": [
[
{
"node": "Email report",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"meta": {
"templateCredsSetupCompleted": false
},
"tags": []
}في Make، أنشئ سيناريو جديدًا وأضف هذه الوحدات بالترتيب:
- Schedule the scenario: 1st of month 8:00
- Stripe › List Charges
- Tools › Set variable / Iterator + Array aggregator (same logic as the Code step)
- Gmail › Send an Email
- كل تشغيل لوحدة يستهلك عمليات (operations) في Make — والباقة المجانية تتضمن حصة شهرية.
- دوال Make المدمجة (map و sum و formatDate…) تغني عن معظم خطوات Code؛ وللمنطق المعقد استخدم وحدة كود.
- قد تختلف أسماء الوحدات والخطوات قليلًا مع تحديث Make و Zapier لتطبيقاتهما.
في Zapier، أنشئ Zap جديدًا وأضف هذه الخطوات بالترتيب:
- Schedule by Zapier — 1st of month 8:00
- Code by Zapier — list charges via the Stripe API
- Code by Zapier — Run JavaScript (paste the code from the Code section)
- Gmail — Send Email
- الـ Zaps التي فيها أكثر من خطوتين تحتاج باقة Zapier مدفوعة.
- الـ Webhooks والفلاتر/المسارات و Code by Zapier ميزات مدفوعة في بعض باقات Zapier.
- Code by Zapier يشغّل JavaScript: أعد استخدام الكود بالأعلى، مع قراءة المدخلات من inputData بدلًا من $json.
- قد تختلف أسماء الوحدات والخطوات قليلًا مع تحديث Make و Zapier لتطبيقاتهما.
نصائح
- إذا كانت مدفوعاتك أكثر من بضع مئات شهريًا، استخدم تقارير Stripe بدلًا من ذلك.
أتمتات مشابهة
المالية والإدارةسهل
تنبيه فوري عند فشل دفعة في Stripe
اعرف بالمدفوعات الفاشلة فورًا وسجّلها للمتابعة.
Stripe → Slack → Google Sheets2 س/شهر
المالية والإدارةسهل
الفواتير المدفوعة في جدول المحاسبة
كل فاتورة مدفوعة في Stripe تُسجَّل تلقائيًا، جاهزة لمحاسبك.
Stripe → Google Sheets5 س/شهر
المالية والإدارةسهل
احفظ مرفقات الفواتير من Gmail في Drive
الفواتير التي تصل بالبريد تُحفظ تلقائيًا في مجلد على Drive.
Gmail → Google Drive3 س/شهر